Skip to content

Commit 93e5599

Browse files
committed
Adding support for CLIENT LIST with ID
Part of redis#1434
1 parent fc621bd commit 93e5599

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Diff for: redis/client.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1243,21 +1243,26 @@ def client_kill_filter(self, _id=None, _type=None, addr=None, skipme=None):
12431243
"<value> must specify at least one filter")
12441244
return self.execute_command('CLIENT KILL', *args)
12451245

1246-
def client_list(self, _type=None):
1246+
def client_list(self, _type=None, client_id=None):
12471247
"""
12481248
Returns a list of currently connected clients.
12491249
If type of client specified, only that type will be returned.
12501250
:param _type: optional. one of the client types (normal, master,
12511251
replica, pubsub)
12521252
"""
12531253
"Returns a list of currently connected clients"
1254+
args = []
12541255
if _type is not None:
12551256
client_types = ('normal', 'master', 'replica', 'pubsub')
12561257
if str(_type).lower() not in client_types:
12571258
raise DataError("CLIENT LIST _type must be one of %r" % (
12581259
client_types,))
1259-
return self.execute_command('CLIENT LIST', b'TYPE', _type)
1260-
return self.execute_command('CLIENT LIST')
1260+
args.append(b'TYPE')
1261+
args.append(_type)
1262+
if client_id is not None:
1263+
args.append(b"ID")
1264+
args.append(client_id)
1265+
return self.execute_command('CLIENT LIST', *args)
12611266

12621267
def client_getname(self):
12631268
"Returns the current connection name"

Diff for: tests/test_commands.py

+8
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ def test_client_list_type(self, r):
290290
clients = r.client_list(_type=client_type)
291291
assert isinstance(clients, list)
292292

293+
@skip_if_server_version_lt('6.2.0')
294+
def test_client_list_client_id(self, r):
295+
clients = r.client_list()
296+
client_id = clients[0]['id']
297+
clients = r.client_list(client_id=client_id)
298+
assert len(clients) == 1
299+
assert 'addr' in clients[0]
300+
293301
@skip_if_server_version_lt('5.0.0')
294302
def test_client_id(self, r):
295303
assert r.client_id() > 0

0 commit comments

Comments
 (0)