Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -792,10 +794,26 @@ def client_getname(self):
"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)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ def test_client_list(self, r):
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
Expand Down