summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvital Fine <79420960+AvitalFineRedis@users.noreply.github.com>2021-07-22 18:51:13 +0300
committerGitHub <noreply@github.com>2021-07-22 18:51:13 +0300
commitad4779eb8200e47a7786f78ca915a246038602c3 (patch)
treea1475e32a127892214ce2ed87f782897229a437b
parent3c244af9e7c820d38135562d9385753f5bbb60e6 (diff)
downloadredis-py-ad4779eb8200e47a7786f78ca915a246038602c3.tar.gz
client_list (#1517)
-rwxr-xr-xredis/client.py12
-rw-r--r--tests/test_commands.py6
2 files changed, 16 insertions, 2 deletions
diff --git a/redis/client.py b/redis/client.py
index 8b1b353..a838d87 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -530,7 +530,7 @@ 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
@@ -538,7 +538,7 @@ def parse_client_info(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
@@ -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,
@@ -1243,6 +1244,13 @@ class Redis:
"<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.
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 088404a..9884035 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -281,6 +281,12 @@ class TestRedisCommands:
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):