Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 19 additions & 0 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,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,
'CONFIG GET': parse_config_get,
'CONFIG RESETSTAT': bool_ok,
'CONFIG SET': bool_ok,
Expand Down Expand Up @@ -707,10 +709,27 @@ 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, 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``"
return self.execute_command('CONFIG GET', pattern)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ 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, 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):
assert r.client_getname() is None
Expand Down