Skip to content

Commit

Permalink
Add waitaof (#2760)
Browse files Browse the repository at this point in the history
* Add waitaof

* Update test_commands.py

add test_waitaof

* Update test_commands.py

Add test_waitaof

* Fix doc string

---------

Co-authored-by: Chayim <chayim@users.noreply.github.com>
Co-authored-by: Igor Malinovskiy <u.glide@gmail.com>
  • Loading branch information
3 people committed Jun 23, 2023
1 parent abc04b5 commit cecf78b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class AbstractRedisCluster:
"SLOWLOG LEN",
"SLOWLOG RESET",
"WAIT",
"WAITAOF",
"SAVE",
"MEMORY PURGE",
"MEMORY MALLOC-STATS",
Expand Down
15 changes: 15 additions & 0 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/test_asyncio/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit cecf78b

Please sign in to comment.