Skip to content

Commit cecf78b

Browse files
aciddustchayimuglide
authored
Add waitaof (#2760)
* Add waitaof * Update test_commands.py add test_waitaof * Update test_commands.py Add test_waitaof * Fix doc string --------- Co-authored-by: Chayim <[email protected]> Co-authored-by: Igor Malinovskiy <[email protected]>
1 parent abc04b5 commit cecf78b

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

redis/cluster.py

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class AbstractRedisCluster:
237237
"SLOWLOG LEN",
238238
"SLOWLOG RESET",
239239
"WAIT",
240+
"WAITAOF",
240241
"SAVE",
241242
"MEMORY PURGE",
242243
"MEMORY MALLOC-STATS",

redis/commands/core.py

+15
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,21 @@ def wait(self, num_replicas: int, timeout: int, **kwargs) -> ResponseT:
13411341
"""
13421342
return self.execute_command("WAIT", num_replicas, timeout, **kwargs)
13431343

1344+
def waitaof(
1345+
self, num_local: int, num_replicas: int, timeout: int, **kwargs
1346+
) -> ResponseT:
1347+
"""
1348+
This command blocks the current client until all previous write
1349+
commands by that client are acknowledged as having been fsynced
1350+
to the AOF of the local Redis and/or at least the specified number
1351+
of replicas.
1352+
1353+
For more information see https://redis.io/commands/waitaof
1354+
"""
1355+
return self.execute_command(
1356+
"WAITAOF", num_local, num_replicas, timeout, **kwargs
1357+
)
1358+
13441359
def hello(self):
13451360
"""
13461361
This function throws a NotImplementedError since it is intentionally

tests/test_asyncio/test_commands.py

+14
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,20 @@ async def test_client_no_touch(self, r: redis.Redis):
461461
with pytest.raises(TypeError):
462462
await r.client_no_touch()
463463

464+
@skip_if_server_version_lt("7.2.0")
465+
@pytest.mark.onlycluster
466+
async def test_waitaof(self, r):
467+
# must return a list of 2 elements
468+
assert len(await r.waitaof(0, 0, 0)) == 2
469+
assert len(await r.waitaof(1, 0, 0)) == 2
470+
assert len(await r.waitaof(1, 0, 1000)) == 2
471+
472+
# value is out of range, value must between 0 and 1
473+
with pytest.raises(exceptions.ResponseError):
474+
await r.waitaof(2, 0, 0)
475+
with pytest.raises(exceptions.ResponseError):
476+
await r.waitaof(-1, 0, 0)
477+
464478
async def test_config_get(self, r: redis.Redis):
465479
data = await r.config_get()
466480
assert "maxmemory" in data

tests/test_commands.py

+14
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,20 @@ def test_client_no_touch(self, r):
704704
with pytest.raises(TypeError):
705705
r.client_no_touch()
706706

707+
@pytest.mark.onlycluster
708+
@skip_if_server_version_lt("7.2.0")
709+
def test_waitaof(self, r):
710+
# must return a list of 2 elements
711+
assert len(r.waitaof(0, 0, 0)) == 2
712+
assert len(r.waitaof(1, 0, 0)) == 2
713+
assert len(r.waitaof(1, 0, 1000)) == 2
714+
715+
# value is out of range, value must between 0 and 1
716+
with pytest.raises(exceptions.ResponseError):
717+
r.waitaof(2, 0, 0)
718+
with pytest.raises(exceptions.ResponseError):
719+
r.waitaof(-1, 0, 0)
720+
707721
@pytest.mark.onlynoncluster
708722
@skip_if_server_version_lt("3.2.0")
709723
def test_client_reply(self, r, r_timeout):

0 commit comments

Comments
 (0)