Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XREADGROUP returns None when stream length is less than COUNT with BLOCK #344

Closed
jjmerchante opened this issue Dec 13, 2024 · 0 comments · Fixed by #346
Closed

XREADGROUP returns None when stream length is less than COUNT with BLOCK #344

jjmerchante opened this issue Dec 13, 2024 · 0 comments · Fixed by #346
Labels
bug Something isn't working

Comments

@jjmerchante
Copy link

Describe the bug

Calling XREADGROUP with COUNT and BLOCK returns None when the number of items in the stream is less than COUNT. On the first call from the _blocking method, it claims the available items, and because the total items are less than COUNT it returns None. On the second call, after BLOCK milliseconds, no items remain in the stream, resulting in 0 items being returned.

if first_pass and (count is None or len(stream_results) < count):

Expected behavior

According to Redis documentation, "When the BLOCK command is passed, but there is data to return at least in one of the streams passed, the command is executed synchronously exactly like if the BLOCK option would be missing."

To Reproduce

For example:

from fakeredis import FakeStrictRedis

connection = FakeStrictRedis()

connection.xadd('test-events', {"message": "hello"})
connection.xadd('test-events', {"message": "bye"})

connection.xgroup_create('test-events', 'group1', id='0', mkstream=True)
messages = connection.xreadgroup(groupname='group1',
    consumername='consumer1',
    streams={'test-events': '>'},
    count=10,
    block=5000
)
# messages is an empty array

Running in a redis-cli doesn't block when the number of items is lower than COUNT and returns the results:

XADD stream 1-1 message "hello"
XGROUP CREATE stream group1 0
XREADGROUP GROUP group1 consumer1 COUNT 10 BLOCK 5000 STREAMS stream '>'

I think len(stream_results) < count should be removed from the condition, but let me know if there’s a specific reason for keeping it.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant