From a667af76e0e89884dd756ce5dd57568cdf2bad74 Mon Sep 17 00:00:00 2001 From: AvitalFineRedis Date: Thu, 22 Jul 2021 10:07:35 +0300 Subject: [PATCH] client_list --- redis/client.py | 12 ++++++++++-- tests/test_commands.py | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/redis/client.py b/redis/client.py index 72178f3068..073153fecd 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 @@ def client_kill_filter(self, _id=None, _type=None, addr=None, skipme=None): " 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 a5a7e45e2f..2a98fa1bbf 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -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):