diff options
| author | Andy McCurdy <andy@andymccurdy.com> | 2018-11-13 12:00:56 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-13 12:00:56 -0800 |
| commit | f2edf59dc5b130a141877c32c0d3236c9f14f77b (patch) | |
| tree | 344ee6051a6d01f39e1a8c7f0a659bca46c653e5 | |
| parent | e69ecbb16a207616e4b7cf5ebdd3075d4eb43e61 (diff) | |
| parent | c91b33954ff2919a20fe00c9cfc6c10c2b0ab453 (diff) | |
| download | redis-py-f2edf59dc5b130a141877c32c0d3236c9f14f77b.tar.gz | |
Merge pull request #1057 from RoeyPrat/roey-client_pause
CLIENT PAUSE and type argument in client_list
| -rwxr-xr-x | redis/client.py | 25 | ||||
| -rw-r--r-- | tests/test_commands.py | 15 |
2 files changed, 39 insertions, 1 deletions
diff --git a/redis/client.py b/redis/client.py index b132336..deb12ad 100755 --- a/redis/client.py +++ b/redis/client.py @@ -465,6 +465,7 @@ class StrictRedis(object): 'CLIENT LIST': parse_client_list, 'CLIENT SETNAME': bool_ok, 'CLIENT UNBLOCK': lambda r: r and int(r) == 1 or False, + 'CLIENT PAUSE': bool_ok, 'CLUSTER ADDSLOTS': bool_ok, 'CLUSTER COUNT-FAILURE-REPORTS': lambda x: int(x), 'CLUSTER COUNTKEYSINSLOT': lambda x: int(x), @@ -787,8 +788,21 @@ 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: + client_types = ('normal', 'master', 'replica', 'pubsub') + if str(_type).lower() not in client_types: + raise RedisError("CLIENT LIST _type must be one of %r" % ( + client_types,)) + return self.execute_command('CLIENT LIST', Token.get_token('TYPE'), + _type) return self.execute_command('CLIENT LIST') def client_getname(self): @@ -815,6 +829,15 @@ class StrictRedis(object): args.append(Token.get_token('ERROR')) return self.execute_command(*args) + def client_pause(self, timeout): + """ + Suspend all the Redis clients for the specified amount of time + :param timeout: milliseconds to pause clients + """ + if not isinstance(timeout, (int, long)): + raise RedisError("CLIENT PAUSE timeout must be an integer") + return self.execute_command('CLIENT PAUSE', str(timeout)) + def config_get(self, pattern="*"): "Return a dictionary of configuration based on the ``pattern``" return self.execute_command('CONFIG GET', pattern) diff --git a/tests/test_commands.py b/tests/test_commands.py index cd3b13d..a264d3a 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 @@ -94,6 +102,13 @@ class TestRedisCommands(object): # we don't know which client ours will be assert 'redis_py_test' in [c['name'] for c in clients] + @skip_if_server_version_lt('2.9.50') + def test_client_pause(self, r): + assert r.client_pause(1) + assert r.client_pause(timeout=1) + with pytest.raises(exceptions.RedisError): + r.client_pause(timeout='not an integer') + def test_config_get(self, r): data = r.config_get() assert 'maxmemory' in data |
