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

Adding support for CLIENT LIST with ID #1505

Merged
merged 10 commits into from
Aug 15, 2021
11 changes: 8 additions & 3 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,21 +1251,26 @@ def client_info(self):
"""
return self.execute_command('CLIENT INFO')

def client_list(self, _type=None):
def client_list(self, _type=None, client_id=None):
"""
Returns a list of currently connected clients.
If type of client specified, only that type will be returned.
:param _type: optional. one of the client types (normal, master,
replica, pubsub)
"""
"Returns a list of currently connected clients"
args = []
if _type is not None:
client_types = ('normal', 'master', 'replica', 'pubsub')
if str(_type).lower() not in client_types:
raise DataError("CLIENT LIST _type must be one of %r" % (
client_types,))
return self.execute_command('CLIENT LIST', b'TYPE', _type)
return self.execute_command('CLIENT LIST')
args.append(b'TYPE')
args.append(_type)
if client_id is not None:
args.append(b"ID")
args.append(client_id)
return self.execute_command('CLIENT LIST', *args)

def client_getname(self):
"Returns the current connection name"
Expand Down
8 changes: 8 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ def test_client_list_type(self, r):
clients = r.client_list(_type=client_type)
assert isinstance(clients, list)

@skip_if_server_version_lt('6.2.0')
def test_client_list_client_id(self, r):
clients = r.client_list()
client_id = clients[0]['id']
clients = r.client_list(client_id=client_id)
assert len(clients) == 1
assert 'addr' in clients[0]

@skip_if_server_version_lt('5.0.0')
def test_client_id(self, r):
assert r.client_id() > 0
Expand Down