Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client_info #1517

Merged
merged 1 commit into from
Jul 22, 2021
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
12 changes: 10 additions & 2 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,15 @@ def parse_client_info(value):
"key1=value1 key2=value2 key3=value3"
"""
client_info = {}
infos = value.split(" ")
infos = str_if_bytes(value).split(" ")
for info in infos:
key, value = info.split("=")
client_info[key] = value

# Those fields are definded as int in networking.c
for int_key in {"id", "age", "idle", "db", "sub", "psub",
"multi", "qbuf", "qbuf-free", "obl",
"oll", "omem"}:
"argv-mem", "oll", "omem", "tot-mem"}:
client_info[int_key] = int(client_info[int_key])
return client_info

Expand Down Expand Up @@ -620,6 +620,7 @@ class Redis:
'CLIENT ID': int,
'CLIENT KILL': parse_client_kill,
'CLIENT LIST': parse_client_list,
'CLIENT INFO': parse_client_info,
'CLIENT SETNAME': bool_ok,
'CLIENT UNBLOCK': lambda r: r and int(r) == 1 or False,
'CLIENT PAUSE': bool_ok,
Expand Down Expand Up @@ -1243,6 +1244,13 @@ def client_kill_filter(self, _id=None, _type=None, addr=None, skipme=None):
"<value> must specify at least one filter")
return self.execute_command('CLIENT KILL', *args)

def client_info(self):
"""
Returns information and statistics about the current
client connection.
"""
return self.execute_command('CLIENT INFO')

def client_list(self, _type=None):
"""
Returns a list of currently connected clients.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ def test_client_list(self, r):
assert isinstance(clients[0], dict)
assert 'addr' in clients[0]

@skip_if_server_version_lt('6.2.0')
def test_client_info(self, r):
info = r.client_info()
assert isinstance(info, dict)
assert 'addr' in info

@skip_if_server_version_lt('5.0.0')
def test_client_list_type(self, r):
with pytest.raises(exceptions.RedisError):
Expand Down