summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xredis/client.py20
-rw-r--r--tests/test_commands.py6
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')