diff options
author | Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com> | 2021-12-22 10:51:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-22 11:51:53 +0200 |
commit | f99744b9049be78bbbe558fbc8ac62d94ac62a4d (patch) | |
tree | 3de41730b0d7d1fb6fe4a26a3ca45bba4b52bf1d | |
parent | e0d3ba5bd73406f80cf89609be45a0006a5382d8 (diff) | |
download | redis-py-f99744b9049be78bbbe558fbc8ac62d94ac62a4d.tar.gz |
Support WRITE in CLIENT PAUSE (#1549)
Co-authored-by: Chayim I. Kirshen <c@kirshen.com>
-rw-r--r-- | redis/commands/core.py | 18 | ||||
-rw-r--r-- | tests/test_commands.py | 7 | ||||
-rw-r--r-- | tests/test_json.py | 1 |
3 files changed, 22 insertions, 4 deletions
diff --git a/redis/commands/core.py b/redis/commands/core.py index 835ea61..6a8cd15 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -510,16 +510,28 @@ class ManagementCommands: 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): """ diff --git a/tests/test_commands.py b/tests/test_commands.py index b8dc69f..510ec7d 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -557,6 +557,13 @@ class TestRedisCommands: 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() diff --git a/tests/test_json.py b/tests/test_json.py index 8bd1d77..6980e67 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -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"} |