summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2018-11-05 15:08:13 -0800
committerGitHub <noreply@github.com>2018-11-05 15:08:13 -0800
commitd7827d82458944a296166a1e04719920eede1473 (patch)
treeaf6a3ee4f92d65d4d6e7f586e7c29fdc3a941aad
parent320afd36c0fd844a63cbff1a3ed3f38085493783 (diff)
parentc34e8e860fd6b99485cb36190a0e225e5a832bff (diff)
downloadredis-py-d7827d82458944a296166a1e04719920eede1473.tar.gz
Merge pull request #1036 from itamarhaber/v5-client-subcommands
Adds v5 new client subcommands
-rwxr-xr-xredis/client.py18
-rw-r--r--tests/test_commands.py11
2 files changed, 29 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py
index 737ae60..f46c7cf 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -461,9 +461,11 @@ class StrictRedis(object):
string_keys_to_dict('BGREWRITEAOF BGSAVE', lambda r: True),
{
'CLIENT GETNAME': lambda r: r and nativestr(r),
+ 'CLIENT ID': int,
'CLIENT KILL': bool_ok,
'CLIENT LIST': parse_client_list,
'CLIENT SETNAME': bool_ok,
+ 'CLIENT UNBLOCK': lambda r: r and int(r) == 1 or False,
'CLUSTER ADDSLOTS': bool_ok,
'CLUSTER COUNT-FAILURE-REPORTS': lambda x: int(x),
'CLUSTER COUNTKEYSINSLOT': lambda x: int(x),
@@ -792,10 +794,26 @@ class StrictRedis(object):
"Returns the current connection name"
return self.execute_command('CLIENT GETNAME')
+ def client_id(self):
+ "Returns the current connection id"
+ return self.execute_command('CLIENT ID')
+
def client_setname(self, name):
"Sets the current connection name"
return self.execute_command('CLIENT SETNAME', name)
+ def client_unblock(self, client_id, error=False):
+ """
+ Unblocks a connection by its client id.
+ If ``error`` is True, unblocks the client with a special error message.
+ If ``error`` is False (default), the client is unblocked using the
+ regular timeout mechanism.
+ """
+ args = ['CLIENT UNBLOCK', int(client_id)]
+ if error:
+ args.append(Token.get_token('ERROR'))
+ return self.execute_command(*args)
+
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 b6636b0..1d0e42e 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -67,6 +67,17 @@ class TestRedisCommands(object):
assert isinstance(clients[0], dict)
assert 'addr' in clients[0]
+ @skip_if_server_version_lt('5.0.0')
+ def test_client_id(self, r):
+ assert r.client_id() > 0
+
+ @skip_if_server_version_lt('5.0.0')
+ def test_client_unblock(self, r):
+ myid = r.client_id()
+ assert not r.client_unblock(myid)
+ assert not r.client_unblock(myid, error=True)
+ assert not r.client_unblock(myid, error=False)
+
@skip_if_server_version_lt('2.6.9')
def test_client_getname(self, r):
assert r.client_getname() is None