summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayim <chayim@users.noreply.github.com>2021-08-15 14:07:44 +0300
committerGitHub <noreply@github.com>2021-08-15 14:07:44 +0300
commit161774be431f2de3c44037698ac311735d559636 (patch)
treea991de85349fb08438e1bfb0ad654e90405df0d8
parente498182b8e208911ea2454838109fb1249b83c5c (diff)
downloadredis-py-161774be431f2de3c44037698ac311735d559636.tar.gz
Adding support for CLIENT LIST with ID (#1505)
-rwxr-xr-xredis/client.py15
-rw-r--r--tests/test_commands.py8
2 files changed, 17 insertions, 6 deletions
diff --git a/redis/client.py b/redis/client.py
index 2d47574..28e3ac1 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -1276,7 +1276,7 @@ class Redis:
"""
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.
@@ -1284,13 +1284,18 @@ class Redis:
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"
@@ -3053,9 +3058,7 @@ class Redis:
raise DataError("ZADD option 'incr' only works when passing a "
"single element/score pair")
if nx is True and (gt is not None or lt is not None):
- raise DataError("Only one of 'nx', 'lt', or 'gt' may be defined.")
- if gt is not None and lt is not None:
- raise DataError("Only one of 'gt' or 'lt' can be set.")
+ raise DataError("Only one of 'nx', 'lt', or 'gr' may be defined.")
pieces = []
options = {}
diff --git a/tests/test_commands.py b/tests/test_commands.py
index dff48b7..9a618aa 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -295,6 +295,14 @@ class TestRedisCommands:
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