Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Implements CLIENT KILL laddr filter (redis/redis-py#1506)

Signed-off-by: Andrew-Chen-Wang <acwangpython@gmail.com>
  • Loading branch information
Andrew-Chen-Wang committed Oct 4, 2021
1 parent 1829beb commit d1bed29
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions aioredis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,7 @@ def client_kill_filter(
_type: Optional[str] = None,
addr: Optional[str] = None,
skipme: Optional[bool] = None,
laddr: Optional[bool] = None,
) -> Awaitable:
"""
Disconnects client(s) using a variety of filter options
Expand All @@ -1369,6 +1370,7 @@ def client_kill_filter(
:param skipme: If True, then the client calling the command
will not get killed even if it is identified by one of the filter
options. If skipme is not provided, the server defaults to skipme=True
:param laddr: Kills a client by its 'local (bind) address:port'
"""
args = []
if _type is not None:
Expand All @@ -1387,6 +1389,8 @@ def client_kill_filter(
args.extend((b"ID", _id))
if addr is not None:
args.extend((b"ADDR", addr))
if laddr is not None:
args.extend((b"LADDR", laddr))
if not args:
raise DataError(
"CLIENT KILL <filter> <value> ... ... <filter> "
Expand Down
25 changes: 25 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,31 @@ async def test_client_list_after_client_setname(self, r: aioredis.Redis):
# we don't know which client ours will be
assert "redis_py_test" in [c["name"] for c in clients]

@skip_if_server_version_lt("6.2.0")
def test_client_kill_filter_by_laddr(self, r: aioredis.Redis, r2: aioredis.Redis):
await r.client_setname("redis-py-c1")
await r2.client_setname("redis-py-c2")
clients = [
client
for client in await r.client_list()
if client.get("name") in ["redis-py-c1", "redis-py-c2"]
]
assert len(clients) == 2

clients_by_name = {client.get("name"): client for client in clients}

client_2_addr = clients_by_name["redis-py-c2"].get("laddr")
resp = await r.client_kill_filter(laddr=client_2_addr)
assert resp == 1

clients = [
client
for client in await r.client_list()
if client.get("name") in ["redis-py-c1", "redis-py-c2"]
]
assert len(clients) == 1
assert clients[0].get("name") == "redis-py-c1"

@skip_if_server_version_lt("2.9.50")
async def test_client_pause(self, r: aioredis.Redis):
assert await r.client_pause(1)
Expand Down

0 comments on commit d1bed29

Please sign in to comment.