Skip to content

Commit 36e00ec

Browse files
authored
Add FULL option to XINFO SUMMARY (#1638)
1 parent cf5c586 commit 36e00ec

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

redis/client.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,24 @@ def parse_xautoclaim(response, **options):
308308
return parse_stream_list(response[1])
309309

310310

311-
def parse_xinfo_stream(response):
311+
def parse_xinfo_stream(response, **options):
312312
data = pairs_to_dict(response, decode_keys=True)
313-
first = data['first-entry']
314-
if first is not None:
315-
data['first-entry'] = (first[0], pairs_to_dict(first[1]))
316-
last = data['last-entry']
317-
if last is not None:
318-
data['last-entry'] = (last[0], pairs_to_dict(last[1]))
313+
if not options.get('full', False):
314+
first = data['first-entry']
315+
if first is not None:
316+
data['first-entry'] = (first[0], pairs_to_dict(first[1]))
317+
last = data['last-entry']
318+
if last is not None:
319+
data['last-entry'] = (last[0], pairs_to_dict(last[1]))
320+
else:
321+
data['entries'] = {
322+
_id: pairs_to_dict(entry)
323+
for _id, entry in data['entries']
324+
}
325+
data['groups'] = [
326+
pairs_to_dict(group, decode_keys=True)
327+
for group in data['groups']
328+
]
319329
return data
320330

321331

redis/commands.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,12 +2050,18 @@ def xinfo_groups(self, name):
20502050
"""
20512051
return self.execute_command('XINFO GROUPS', name)
20522052

2053-
def xinfo_stream(self, name):
2053+
def xinfo_stream(self, name, full=False):
20542054
"""
20552055
Returns general information about the stream.
20562056
name: name of the stream.
2057+
full: optional boolean, false by default. Return full summary
20572058
"""
2058-
return self.execute_command('XINFO STREAM', name)
2059+
pieces = [name]
2060+
options = {}
2061+
if full:
2062+
pieces.append(b'FULL')
2063+
options = {'full': full}
2064+
return self.execute_command('XINFO STREAM', *pieces, **options)
20592065

20602066
def xlen(self, name):
20612067
"""

tests/test_commands.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,6 +3156,18 @@ def test_xinfo_stream(self, r):
31563156
assert info['first-entry'] == get_stream_message(r, stream, m1)
31573157
assert info['last-entry'] == get_stream_message(r, stream, m2)
31583158

3159+
@skip_if_server_version_lt('6.0.0')
3160+
def test_xinfo_stream_full(self, r):
3161+
stream = 'stream'
3162+
group = 'group'
3163+
m1 = r.xadd(stream, {'foo': 'bar'})
3164+
r.xgroup_create(stream, group, 0)
3165+
info = r.xinfo_stream(stream, full=True)
3166+
3167+
assert info['length'] == 1
3168+
assert m1 in info['entries']
3169+
assert len(info['groups']) == 1
3170+
31593171
@skip_if_server_version_lt('5.0.0')
31603172
def test_xlen(self, r):
31613173
stream = 'stream'

0 commit comments

Comments
 (0)