Skip to content

Support WRITE in CLIENT PAUSE #1549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,16 +510,28 @@ def client_unblock(self, client_id, error=False, **kwargs):
args.append(b"ERROR")
return self.execute_command(*args, **kwargs)

def client_pause(self, timeout, **kwargs):
def client_pause(self, timeout, all=True, **kwargs):
"""
Suspend all the Redis clients for the specified amount of time
:param timeout: milliseconds to pause clients

For more information check https://redis.io/commands/client-pause
"""
:param all: If true (default) all client commands are blocked.
otherwise, clients are only blocked if they attempt to execute
a write command.
For the WRITE mode, some commands have special behavior:
EVAL/EVALSHA: Will block client for all scripts.
PUBLISH: Will block client.
PFCOUNT: Will block client.
WAIT: Acknowledgments will be delayed, so this command will
appear blocked.
"""
args = ["CLIENT PAUSE", str(timeout)]
if not isinstance(timeout, int):
raise DataError("CLIENT PAUSE timeout must be an integer")
return self.execute_command("CLIENT PAUSE", str(timeout), **kwargs)
if not all:
args.append("WRITE")
return self.execute_command(*args, **kwargs)

def client_unpause(self, **kwargs):
"""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,13 @@ def test_client_pause(self, r):
with pytest.raises(exceptions.RedisError):
r.client_pause(timeout="not an integer")

@skip_if_server_version_lt("6.2.0")
def test_client_pause_all(self, r, r2):
assert r.client_pause(1, all=False)
assert r2.set("foo", "bar")
assert r2.get("foo") == b"bar"
assert r.get("foo") == b"bar"

@pytest.mark.onlynoncluster
@skip_if_server_version_lt("6.2.0")
@skip_if_redis_enterprise()
Expand Down
1 change: 0 additions & 1 deletion tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,5 @@ def test_set_path(client):
open(nojsonfile, "a+").write("hello")

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