Skip to content

Commit 40bc256

Browse files
committed
Implements CLIENT KILL laddr filter (redis#1506)
1 parent 3d4740a commit 40bc256

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

redis/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,14 +1210,16 @@ def client_kill(self, address):
12101210
"Disconnects the client at ``address`` (ip:port)"
12111211
return self.execute_command('CLIENT KILL', address)
12121212

1213-
def client_kill_filter(self, _id=None, _type=None, addr=None, skipme=None):
1213+
def client_kill_filter(self, _id=None, _type=None, addr=None,
1214+
skipme=None, laddr=None):
12141215
"""
12151216
Disconnects client(s) using a variety of filter options
12161217
:param id: Kills a client by its unique ID field
12171218
:param type: Kills a client by type where type is one of 'normal',
12181219
'master', 'slave' or 'pubsub'
12191220
:param addr: Kills a client by its 'address:port'
12201221
:param skipme: If True, then the client calling the command
1222+
:param laddr: Kills a cient by its 'local (bind) address:port'
12211223
will not get killed even if it is identified by one of the filter
12221224
options. If skipme is not provided, the server defaults to skipme=True
12231225
"""
@@ -1239,6 +1241,8 @@ def client_kill_filter(self, _id=None, _type=None, addr=None, skipme=None):
12391241
args.extend((b'ID', _id))
12401242
if addr is not None:
12411243
args.extend((b'ADDR', addr))
1244+
if laddr is not None:
1245+
args.extend((b'LADDR', laddr))
12421246
if not args:
12431247
raise DataError("CLIENT KILL <filter> <value> ... ... <filter> "
12441248
"<value> must specify at least one filter")

tests/test_commands.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,26 @@ def test_client_list_after_client_setname(self, r):
395395
# we don't know which client ours will be
396396
assert 'redis_py_test' in [c['name'] for c in clients]
397397

398+
@skip_if_server_version_lt('6.2.0')
399+
def test_client_kill_filter_by_laddr(self, r, r2):
400+
r.client_setname('redis-py-c1')
401+
r2.client_setname('redis-py-c2')
402+
clients = [client for client in r.client_list()
403+
if client.get('name') in ['redis-py-c1', 'redis-py-c2']]
404+
assert len(clients) == 2
405+
406+
clients_by_name = dict([(client.get('name'), client)
407+
for client in clients])
408+
409+
client_2_addr = clients_by_name['redis-py-c2'].get('laddr')
410+
resp = r.client_kill_filter(laddr=client_2_addr)
411+
assert resp == 1
412+
413+
clients = [client for client in r.client_list()
414+
if client.get('name') in ['redis-py-c1', 'redis-py-c2']]
415+
assert len(clients) == 1
416+
assert clients[0].get('name') == 'redis-py-c1'
417+
398418
@skip_if_server_version_lt('2.9.50')
399419
def test_client_pause(self, r):
400420
assert r.client_pause(1)

0 commit comments

Comments
 (0)