Skip to content

Commit 161774b

Browse files
authored
Adding support for CLIENT LIST with ID (#1505)
1 parent e498182 commit 161774b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

redis/client.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1276,21 +1276,26 @@ def client_info(self):
12761276
"""
12771277
return self.execute_command('CLIENT INFO')
12781278

1279-
def client_list(self, _type=None):
1279+
def client_list(self, _type=None, client_id=None):
12801280
"""
12811281
Returns a list of currently connected clients.
12821282
If type of client specified, only that type will be returned.
12831283
:param _type: optional. one of the client types (normal, master,
12841284
replica, pubsub)
12851285
"""
12861286
"Returns a list of currently connected clients"
1287+
args = []
12871288
if _type is not None:
12881289
client_types = ('normal', 'master', 'replica', 'pubsub')
12891290
if str(_type).lower() not in client_types:
12901291
raise DataError("CLIENT LIST _type must be one of %r" % (
12911292
client_types,))
1292-
return self.execute_command('CLIENT LIST', b'TYPE', _type)
1293-
return self.execute_command('CLIENT LIST')
1293+
args.append(b'TYPE')
1294+
args.append(_type)
1295+
if client_id is not None:
1296+
args.append(b"ID")
1297+
args.append(client_id)
1298+
return self.execute_command('CLIENT LIST', *args)
12941299

12951300
def client_getname(self):
12961301
"Returns the current connection name"
@@ -3053,9 +3058,7 @@ def zadd(self, name, mapping, nx=False, xx=False, ch=False, incr=False,
30533058
raise DataError("ZADD option 'incr' only works when passing a "
30543059
"single element/score pair")
30553060
if nx is True and (gt is not None or lt is not None):
3056-
raise DataError("Only one of 'nx', 'lt', or 'gt' may be defined.")
3057-
if gt is not None and lt is not None:
3058-
raise DataError("Only one of 'gt' or 'lt' can be set.")
3061+
raise DataError("Only one of 'nx', 'lt', or 'gr' may be defined.")
30593062

30603063
pieces = []
30613064
options = {}

tests/test_commands.py

+8
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ def test_client_list_type(self, r):
295295
clients = r.client_list(_type=client_type)
296296
assert isinstance(clients, list)
297297

298+
@skip_if_server_version_lt('6.2.0')
299+
def test_client_list_client_id(self, r):
300+
clients = r.client_list()
301+
client_id = clients[0]['id']
302+
clients = r.client_list(client_id=client_id)
303+
assert len(clients) == 1
304+
assert 'addr' in clients[0]
305+
298306
@skip_if_server_version_lt('5.0.0')
299307
def test_client_id(self, r):
300308
assert r.client_id() > 0

0 commit comments

Comments
 (0)