Skip to content

Commit f99744b

Browse files
Support WRITE in CLIENT PAUSE (#1549)
Co-authored-by: Chayim I. Kirshen <[email protected]>
1 parent e0d3ba5 commit f99744b

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

redis/commands/core.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,16 +510,28 @@ def client_unblock(self, client_id, error=False, **kwargs):
510510
args.append(b"ERROR")
511511
return self.execute_command(*args, **kwargs)
512512

513-
def client_pause(self, timeout, **kwargs):
513+
def client_pause(self, timeout, all=True, **kwargs):
514514
"""
515515
Suspend all the Redis clients for the specified amount of time
516516
:param timeout: milliseconds to pause clients
517517
518518
For more information check https://redis.io/commands/client-pause
519-
"""
519+
:param all: If true (default) all client commands are blocked.
520+
otherwise, clients are only blocked if they attempt to execute
521+
a write command.
522+
For the WRITE mode, some commands have special behavior:
523+
EVAL/EVALSHA: Will block client for all scripts.
524+
PUBLISH: Will block client.
525+
PFCOUNT: Will block client.
526+
WAIT: Acknowledgments will be delayed, so this command will
527+
appear blocked.
528+
"""
529+
args = ["CLIENT PAUSE", str(timeout)]
520530
if not isinstance(timeout, int):
521531
raise DataError("CLIENT PAUSE timeout must be an integer")
522-
return self.execute_command("CLIENT PAUSE", str(timeout), **kwargs)
532+
if not all:
533+
args.append("WRITE")
534+
return self.execute_command(*args, **kwargs)
523535

524536
def client_unpause(self, **kwargs):
525537
"""

tests/test_commands.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,13 @@ def test_client_pause(self, r):
557557
with pytest.raises(exceptions.RedisError):
558558
r.client_pause(timeout="not an integer")
559559

560+
@skip_if_server_version_lt("6.2.0")
561+
def test_client_pause_all(self, r, r2):
562+
assert r.client_pause(1, all=False)
563+
assert r2.set("foo", "bar")
564+
assert r2.get("foo") == b"bar"
565+
assert r.get("foo") == b"bar"
566+
560567
@pytest.mark.onlynoncluster
561568
@skip_if_server_version_lt("6.2.0")
562569
@skip_if_redis_enterprise()

tests/test_json.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,5 @@ def test_set_path(client):
14281428
open(nojsonfile, "a+").write("hello")
14291429

14301430
result = {jsonfile: True, nojsonfile: False}
1431-
print(result)
14321431
assert client.json().set_path(Path.rootPath(), root) == result
14331432
assert client.json().get(jsonfile.rsplit(".")[0]) == {"hello": "world"}

0 commit comments

Comments
 (0)