Skip to content

Commit

Permalink
fix:xreadgroup when stream length is less than COUNT (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla authored Dec 15, 2024
1 parent b4f49d8 commit 6153c1b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/about/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ tags:
toc_depth: 2
---

## v2.26.2

### 🐛 Bug Fixes

- Fix bug in `xreadgroup` when stream length is less than COUNT with BLOCK #344

## v2.26.1

### 🐛 Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion fakeredis/commands_mixins/streams_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def _xreadgroup(
res: List[Any] = list()
for group, stream_name, start_id in group_params:
stream_results = group.group_read(consumer_name, start_id, count, noack)
if first_pass and (count is None or len(stream_results) < count):
if first_pass and (count is None):
return None
if len(stream_results) > 0 or start_id != b">":
res.append([stream_name, stream_results])
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packages = [
{ include = "fakeredis" },
{ include = "LICENSE", to = "fakeredis" },
]
version = "2.26.1"
version = "2.26.2"
description = "Python implementation of redis API, can be used for testing purposes."
readme = "README.md"
keywords = ["redis", "RedisJson", "RedisBloom", "tests", "redis-stack"]
Expand Down
11 changes: 11 additions & 0 deletions test/test_mixins/test_streams_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,14 @@ def test_stream_ttl(r: redis.Redis):
assert r.xread(streams={stream: 0}) == expected
assert r.xtrim(stream, 0) == 1
assert r.ttl(stream) == -1


def test_xreadgroup_length_less_than_count(r: redis.Redis):
r.xadd("test-events", {"message": "hello"})
r.xadd("test-events", {"message": "bye"})

r.xgroup_create("test-events", "group1", id="0", mkstream=True)
messages = r.xreadgroup(
groupname="group1", consumername="consumer1", streams={"test-events": ">"}, count=10, block=2000
)
assert len(messages) == 1

0 comments on commit 6153c1b

Please sign in to comment.