diff options
| author | Roey Prat <roey.prat@redislabs.com> | 2018-11-05 16:33:08 +0200 |
|---|---|---|
| committer | Roey Prat <roey.prat@redislabs.com> | 2018-11-07 10:19:08 +0200 |
| commit | 66ab23ddd70115ffb29012f60a84b5235edcaab2 (patch) | |
| tree | c4bd28cd4970b4baf0ca1c67eb1fbf499532bf42 | |
| parent | 5e033f3e716120be992dd26d61b1f7f904331cac (diff) | |
| download | redis-py-66ab23ddd70115ffb29012f60a84b5235edcaab2.tar.gz | |
Implements type argument in client_list
| -rwxr-xr-x | redis/client.py | 17 | ||||
| -rw-r--r-- | tests/test_commands.py | 8 |
2 files changed, 21 insertions, 4 deletions
diff --git a/redis/client.py b/redis/client.py index 81d8356..f3dcc2c 100755 --- a/redis/client.py +++ b/redis/client.py @@ -464,11 +464,8 @@ class StrictRedis(object): 'CLIENT KILL': bool_ok, 'CLIENT LIST': parse_client_list, 'CLIENT SETNAME': bool_ok, -<<<<<<< HEAD 'CLIENT UNBLOCK': lambda r: r and int(r) == 1 or False, -======= 'CLIENT PAUSE': bool_ok, ->>>>>>> 7c3a128... Implements CLIENT PAUSE 'CLUSTER ADDSLOTS': bool_ok, 'CLUSTER COUNT-FAILURE-REPORTS': lambda x: int(x), 'CLUSTER COUNTKEYSINSLOT': lambda x: int(x), @@ -789,8 +786,20 @@ class StrictRedis(object): "Disconnects the client at ``address`` (ip:port)" return self.execute_command('CLIENT KILL', address) - def client_list(self): + def client_list(self, _type=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" + if _type is not None: + if _type not in ['normal', 'master', 'replica', 'pubsub']: + raise RedisError("CLIENT LIST _type must be one of ('normal'," + " 'master', 'replica', 'pubsub')") + return self.execute_command('CLIENT LIST', Token.get_token('TYPE'), + _type) return self.execute_command('CLIENT LIST') def client_getname(self): diff --git a/tests/test_commands.py b/tests/test_commands.py index abe6143..1686879 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -68,6 +68,14 @@ class TestRedisCommands(object): assert 'addr' in clients[0] @skip_if_server_version_lt('5.0.0') + def test_client_list_type(self, r): + with pytest.raises(exceptions.RedisError): + r.client_list(_type='not a client type') + for client_type in ['normal', 'master', 'replica', 'pubsub']: + clients = r.client_list(_type=client_type) + assert isinstance(clients, list) + + @skip_if_server_version_lt('5.0.0') def test_client_id(self, r): assert r.client_id() > 0 |
