diff --git a/redis/cluster.py b/redis/cluster.py index dfa2647819..487e3d7f85 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 af5384e9ef..392ddb542c 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 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 + """ + return self.execute_command( + "WAITAOF", num_local, num_replicas, timeout, **kwargs + ) + def hello(self): """ This function throws a NotImplementedError since it is intentionally 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 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):