From 0a80dc69be5f51bc604fb7aa22f003be0186059b Mon Sep 17 00:00:00 2001 From: d3fau1t Date: Sun, 14 May 2023 20:20:34 +0900 Subject: [PATCH 1/4] Add waitaof --- redis/cluster.py | 1 + redis/commands/core.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/redis/cluster.py b/redis/cluster.py index 2ab173ded9..be8e4623a7 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -237,6 +237,7 @@ class AbstractRedisCluster: "SLOWLOG LEN", "SLOWLOG RESET", "WAIT", + "WAITAOF", "SAVE", "MEMORY PURGE", "MEMORY MALLOC-STATS", diff --git a/redis/commands/core.py b/redis/commands/core.py index f2d7bf2eb4..d829a162ab 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -1341,6 +1341,21 @@ def wait(self, num_replicas: int, timeout: int, **kwargs) -> ResponseT: """ return self.execute_command("WAIT", num_replicas, timeout, **kwargs) + def waitaof( + self, num_local: int, num_replicas: int, timeout: int, **kwargs + ) -> ResponseT: + """ + This command block until the next fsync on AOF file + for the specified `num_replicas` or if the "number of replicas" parameter is 0, + blocks until the next fsync on AOF file for the current Redis instance. + If AOF persistence is not enabled, the command returns an error. + + For more information see https://redis.io/commands/waitaof + """ + return self.execute_command( + "WAITAOF", num_local, num_replicas, timeout, **kwargs + ) + def hello(self): """ This function throws a NotImplementedError since it is intentionally From a9d6860b4b97273040b03142eda1214b23960223 Mon Sep 17 00:00:00 2001 From: Seongchuel Ahn Date: Thu, 8 Jun 2023 20:20:02 +0900 Subject: [PATCH 2/4] Update test_commands.py add test_waitaof --- tests/test_commands.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index 4e2ac5b041..2213e81f72 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -704,6 +704,20 @@ def test_client_no_touch(self, r): with pytest.raises(TypeError): r.client_no_touch() + @pytest.mark.onlycluster + @skip_if_server_version_lt("7.2.0") + def test_waitaof(self, r): + # must return a list of 2 elements + assert len(r.waitaof(0, 0, 0)) == 2 + assert len(r.waitaof(1, 0, 0)) == 2 + assert len(r.waitaof(1, 0, 1000)) == 2 + + # value is out of range, value must between 0 and 1 + with pytest.raises(exceptions.ResponseError): + r.waitaof(2, 0, 0) + with pytest.raises(exceptions.ResponseError): + r.waitaof(-1, 0, 0) + @pytest.mark.onlynoncluster @skip_if_server_version_lt("3.2.0") def test_client_reply(self, r, r_timeout): From 6a2ae645d336fffd7dbf96f1e11fb7201582a814 Mon Sep 17 00:00:00 2001 From: Seongchuel Ahn Date: Thu, 8 Jun 2023 20:21:42 +0900 Subject: [PATCH 3/4] Update test_commands.py Add test_waitaof --- tests/test_asyncio/test_commands.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_asyncio/test_commands.py b/tests/test_asyncio/test_commands.py index 89a8525887..c0259680c0 100644 --- a/tests/test_asyncio/test_commands.py +++ b/tests/test_asyncio/test_commands.py @@ -461,6 +461,20 @@ async def test_client_no_touch(self, r: redis.Redis): with pytest.raises(TypeError): await r.client_no_touch() + @skip_if_server_version_lt("7.2.0") + @pytest.mark.onlycluster + async def test_waitaof(self, r): + # must return a list of 2 elements + assert len(await r.waitaof(0, 0, 0)) == 2 + assert len(await r.waitaof(1, 0, 0)) == 2 + assert len(await r.waitaof(1, 0, 1000)) == 2 + + # value is out of range, value must between 0 and 1 + with pytest.raises(exceptions.ResponseError): + await r.waitaof(2, 0, 0) + with pytest.raises(exceptions.ResponseError): + await r.waitaof(-1, 0, 0) + async def test_config_get(self, r: redis.Redis): data = await r.config_get() assert "maxmemory" in data From 16ddf847781cbdcb66bc69835725c6980d2f5642 Mon Sep 17 00:00:00 2001 From: Igor Malinovskiy Date: Fri, 23 Jun 2023 13:29:05 +0200 Subject: [PATCH 4/4] Fix doc string --- redis/commands/core.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/redis/commands/core.py b/redis/commands/core.py index 3f4f1e2907..392ddb542c 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -1345,10 +1345,10 @@ def waitaof( self, num_local: int, num_replicas: int, timeout: int, **kwargs ) -> ResponseT: """ - This command block until the next fsync on AOF file - for the specified `num_replicas` or if the "number of replicas" parameter is 0, - blocks until the next fsync on AOF file for the current Redis instance. - If AOF persistence is not enabled, the command returns an error. + This command blocks the current client until all previous write + commands by that client are acknowledged as having been fsynced + to the AOF of the local Redis and/or at least the specified number + of replicas. For more information see https://redis.io/commands/waitaof """