Skip to content

Commit ad4779e

Browse files
client_list (#1517)
1 parent 3c244af commit ad4779e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

redis/client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,15 +530,15 @@ def parse_client_info(value):
530530
"key1=value1 key2=value2 key3=value3"
531531
"""
532532
client_info = {}
533-
infos = value.split(" ")
533+
infos = str_if_bytes(value).split(" ")
534534
for info in infos:
535535
key, value = info.split("=")
536536
client_info[key] = value
537537

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

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

1247+
def client_info(self):
1248+
"""
1249+
Returns information and statistics about the current
1250+
client connection.
1251+
"""
1252+
return self.execute_command('CLIENT INFO')
1253+
12461254
def client_list(self, _type=None):
12471255
"""
12481256
Returns a list of currently connected clients.

tests/test_commands.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ def test_client_list(self, r):
281281
assert isinstance(clients[0], dict)
282282
assert 'addr' in clients[0]
283283

284+
@skip_if_server_version_lt('6.2.0')
285+
def test_client_info(self, r):
286+
info = r.client_info()
287+
assert isinstance(info, dict)
288+
assert 'addr' in info
289+
284290
@skip_if_server_version_lt('5.0.0')
285291
def test_client_list_type(self, r):
286292
with pytest.raises(exceptions.RedisError):

0 commit comments

Comments
 (0)