Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add waitaof #2760

Merged
merged 6 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading