diff options
author | Itamar Haber <itamar@redislabs.com> | 2018-10-05 20:20:55 +0300 |
---|---|---|
committer | Itamar Haber <itamar@redislabs.com> | 2018-10-05 20:20:55 +0300 |
commit | 7a8a85245d2e55c2c97290175bd6d6f98976ff5f (patch) | |
tree | 0fa0245ada6e6fd9c1ca105b0ff2164e95a3f5d9 | |
parent | 80beebbd22a9a12da5347acbd6184f2e722ab8fa (diff) | |
download | redis-py-7a8a85245d2e55c2c97290175bd6d6f98976ff5f.tar.gz |
Adds unblock reason support
Signed-off-by: Itamar Haber <itamar@redislabs.com>
-rwxr-xr-x | redis/client.py | 17 | ||||
-rw-r--r-- | tests/test_commands.py | 6 |
2 files changed, 18 insertions, 5 deletions
diff --git a/redis/client.py b/redis/client.py index 2ea28c3..416d34b 100755 --- a/redis/client.py +++ b/redis/client.py @@ -402,7 +402,7 @@ class StrictRedis(object): 'CLIENT KILL': bool_ok, 'CLIENT LIST': parse_client_list, 'CLIENT SETNAME': bool_ok, - 'CLIENT UNBLOCK': int, + 'CLIENT UNBLOCK': lambda r: r and int(r) == 1 or False, 'CONFIG GET': parse_config_get, 'CONFIG RESETSTAT': bool_ok, 'CONFIG SET': bool_ok, @@ -717,9 +717,18 @@ class StrictRedis(object): "Sets the current connection name" return self.execute_command('CLIENT SETNAME', name) - def client_unblock(self, client_id): - "Unblocks a connection by its client id" - return self.execute_command('CLIENT UNBLOCK', client_id) + def client_unblock(self, client_id, reason=None): + """ + Unblocks a connection by its client id + + The ``reason`` argument, if set to ``'error'``, unblocks the client + with a special error message. When set to ``'timeout'`` or if not set, + the client is unblocked using the regular timeout mechanism. + """ + args = ['CLIENT UNBLOCK', int(client_id)] + if reason is not None and isinstance(reason, str): + args.append(reason) + return self.execute_command(*args) def config_get(self, pattern="*"): "Return a dictionary of configuration based on the ``pattern``" diff --git a/tests/test_commands.py b/tests/test_commands.py index 01dbd79..724928f 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -66,7 +66,11 @@ class TestRedisCommands(object): @skip_if_server_version_lt('5.0.0') def test_client_unblock(self, r): myid = r.client_id() - assert r.client_unblock(myid) == 0 + assert not r.client_unblock(myid) + assert not r.client_unblock(myid, reason='TIMEOUT') + assert not r.client_unblock(myid, reason='ERROR') + with pytest.raises(exceptions.ResponseError): + r.client_unblock(myid, reason='foobar') @skip_if_server_version_lt('2.6.9') def test_client_getname(self, r): |