diff options
author | Agustin Marquez <agusdmb@gmail.com> | 2021-10-25 08:28:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-25 09:28:50 +0300 |
commit | 36e00ec4e22a9f947e099affdfdc79862ac7ca08 (patch) | |
tree | 033f6af87bc7726b5d431015ea8b6c05c2053ec7 | |
parent | cf5c5865bb9947498f3810b028628f3d2ab14030 (diff) | |
download | redis-py-36e00ec4e22a9f947e099affdfdc79862ac7ca08.tar.gz |
Add FULL option to XINFO SUMMARY (#1638)
-rwxr-xr-x | redis/client.py | 24 | ||||
-rw-r--r-- | redis/commands.py | 10 | ||||
-rw-r--r-- | tests/test_commands.py | 12 |
3 files changed, 37 insertions, 9 deletions
diff --git a/redis/client.py b/redis/client.py index fde153d..a6bd183 100755 --- a/redis/client.py +++ b/redis/client.py @@ -308,14 +308,24 @@ def parse_xautoclaim(response, **options): return parse_stream_list(response[1]) -def parse_xinfo_stream(response): +def parse_xinfo_stream(response, **options): data = pairs_to_dict(response, decode_keys=True) - first = data['first-entry'] - if first is not None: - data['first-entry'] = (first[0], pairs_to_dict(first[1])) - last = data['last-entry'] - if last is not None: - data['last-entry'] = (last[0], pairs_to_dict(last[1])) + if not options.get('full', False): + first = data['first-entry'] + if first is not None: + data['first-entry'] = (first[0], pairs_to_dict(first[1])) + last = data['last-entry'] + if last is not None: + data['last-entry'] = (last[0], pairs_to_dict(last[1])) + else: + data['entries'] = { + _id: pairs_to_dict(entry) + for _id, entry in data['entries'] + } + data['groups'] = [ + pairs_to_dict(group, decode_keys=True) + for group in data['groups'] + ] return data diff --git a/redis/commands.py b/redis/commands.py index f2c1538..f5243e4 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -2050,12 +2050,18 @@ class Commands: """ return self.execute_command('XINFO GROUPS', name) - def xinfo_stream(self, name): + def xinfo_stream(self, name, full=False): """ Returns general information about the stream. name: name of the stream. + full: optional boolean, false by default. Return full summary """ - return self.execute_command('XINFO STREAM', name) + pieces = [name] + options = {} + if full: + pieces.append(b'FULL') + options = {'full': full} + return self.execute_command('XINFO STREAM', *pieces, **options) def xlen(self, name): """ diff --git a/tests/test_commands.py b/tests/test_commands.py index fec453f..694090e 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -3156,6 +3156,18 @@ class TestRedisCommands: assert info['first-entry'] == get_stream_message(r, stream, m1) assert info['last-entry'] == get_stream_message(r, stream, m2) + @skip_if_server_version_lt('6.0.0') + def test_xinfo_stream_full(self, r): + stream = 'stream' + group = 'group' + m1 = r.xadd(stream, {'foo': 'bar'}) + r.xgroup_create(stream, group, 0) + info = r.xinfo_stream(stream, full=True) + + assert info['length'] == 1 + assert m1 in info['entries'] + assert len(info['groups']) == 1 + @skip_if_server_version_lt('5.0.0') def test_xlen(self, r): stream = 'stream' |