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

Reading multiple streams does not give expected result #309

Closed
mguijarr opened this issue May 13, 2024 · 3 comments
Closed

Reading multiple streams does not give expected result #309

mguijarr opened this issue May 13, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@mguijarr
Copy link

mguijarr commented May 13, 2024

Describe the bug

When reading multiple streams, if block is set fakeredis stops at the first stream whereas the real Redis
gives output for all streams as expected.

To Reproduce

import redis
from fakeredis import FakeServer, FakeStrictRedis

def main():
    fake_server = FakeServer()
    fake_client = FakeStrictRedis(server=fake_server)
    real_client = redis.Redis(host="localhost", port=6379, db=1)

    k = "key"
    k2 = "key2"
    streams = {k: "0", k2: "0"}

    real_client.xadd(k, {"value":1234})
    real_client.xadd(k2, {"value": 5678})
    res = real_client.xread(streams, block=200)
    assert len(res) == 2
    print("Success: read 2 streams", res)

    fake_client.xadd(k, {"value":1234})
    fake_client.xadd(k2, {"value": 5678})
    res = fake_client.xread(streams, block=200)
    assert len(res) == 2, "Could not read 2 streams"

Expected behavior

Expected behaviour: the assertion should not raise, res for fake_client should be the same as res for real_client

It can be narrowed down in file fakeredis/commands_mixins/streams_mixin.py in method _xread:

...
for stream_name, start_id in stream_start_id_list:
            item = CommandItem(stream_name, self._db, item=self._db.get(stream_name), default=None)
            stream_results = self._xrange(item.value, start_id, max_inf, False, count)
            if len(stream_results) > 0:
                res.append([item.key, stream_results])
            if first_pass and (count is None): ###
                return res                                    ### why the early exit ? there might be other items in list
...

Note: when removing block in fake_client.xread in the example above, it seems to work ❓ 🤔 (except that in real life the code really needs block)

Desktop (please complete the following information):

  • OS: ArchLinux
  • python version 3.11
  • redis-py version 5.0.1
  • fakeredis 2.23.1

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@mguijarr mguijarr added the bug Something isn't working label May 13, 2024
@cunla cunla closed this as completed in 8675b5d May 14, 2024
@mguijarr
Copy link
Author

Thanks @cunla 👍🏻

@mguijarr
Copy link
Author

I would like to know if there is going to be a new release with this bug fix soon? And thanks again! The simplified version looks nice 👍🏻

@cunla
Copy link
Owner

cunla commented May 15, 2024

This or next weekend

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

No branches or pull requests

2 participants