diff options
author | Roey Prat <roey.prat@redislabs.com> | 2020-10-26 14:43:24 +0200 |
---|---|---|
committer | Roey Prat <roey.prat@redislabs.com> | 2020-11-02 18:51:28 +0200 |
commit | 8d4b3d49d0d641f8a0454de35c89886a33212829 (patch) | |
tree | 37f858ef95613f19eef06126189a809592f1d7dd | |
parent | 6e85707e79d194053f18af5b4c7dde0a5b99c5fe (diff) | |
download | redis-py-roey/slowlog_get_fields.tar.gz |
#1374 slowlog get - include fields added in Redis version 4roey/slowlog_get_fields
-rwxr-xr-x | redis/client.py | 20 | ||||
-rw-r--r-- | tests/test_commands.py | 6 |
2 files changed, 20 insertions, 6 deletions
diff --git a/redis/client.py b/redis/client.py index 08b0314..5bac3bb 100755 --- a/redis/client.py +++ b/redis/client.py @@ -400,12 +400,20 @@ def parse_zscan(response, **options): def parse_slowlog_get(response, **options): space = ' ' if options.get('decode_responses', False) else b' ' - return [{ - 'id': item[0], - 'start_time': int(item[1]), - 'duration': int(item[2]), - 'command': space.join(item[3]) - } for item in response] + parsed_items = [] + for item in response: + parsed_item = { + 'id': item[0], + 'start_time': int(item[1]), + 'duration': int(item[2]), + 'command': space.join(item[3]) + } + if len(item) >= 5: + parsed_item['client_address'] = str_if_bytes(item[4]) + if len(item) >= 6: + parsed_item['client_name'] = str_if_bytes(item[5]) + parsed_items.append(parsed_item) + return parsed_items def parse_cluster_info(response, **options): diff --git a/tests/test_commands.py b/tests/test_commands.py index 2113078..2cc59e4 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -447,6 +447,9 @@ class TestRedisCommands: def test_ping(self, r): assert r.ping() + # slowlog get was available since 2.2.12 + # but socket address and name were added in version 4.0 + @skip_if_server_version_lt('4.0.0') def test_slowlog_get(self, r, slowlog): assert r.slowlog_reset() unicode_string = chr(3456) + 'abcd' + chr(3421) @@ -468,6 +471,9 @@ class TestRedisCommands: assert isinstance(slowlog[0]['start_time'], int) assert isinstance(slowlog[0]['duration'], int) + assert isinstance(slowlog[0]['client_address'], str) + assert isinstance(slowlog[0]['client_name'], str) + def test_slowlog_get_limit(self, r, slowlog): assert r.slowlog_reset() r.get('foo') |