cunla / fakeredis-py

Implementation of Redis in python without having a Redis server running. Fully compatible with using redis-py.
https://fakeredis.moransoftware.ca/
BSD 3-Clause "New" or "Revised" License
298 stars 48 forks source link

XREAD command returns empty list if count is bigger than number of messages #256

Closed sveta-afanaseva closed 11 months ago

sveta-afanaseva commented 11 months ago

Describe the bug Command XREAD returns empty list when COUNT is bigger than count of messages in stream. However, in redis python sdk it works another way (it returns all messages from the stream)

Some proofs https://github.com/redis/redis-py/blob/emb-examples/doctests/dt_stream.py#L43 https://redis.io/docs/data-types/streams/

To Reproduce Steps to reproduce the behavior:

  1. Create FakeRedis object
  2. Add message in stream with command xadd
  3. Call xread command for your stream with argument count=100
  4. Get empty list

Expected behavior Expected list of all messages in stream

Desktop (please complete the following information):

cunla commented 11 months ago

Hi, can you provide the test for it? to run against real redis and fakeredis?

sveta-afanaseva commented 11 months ago

Yes, try this

from fakeredis import FakeRedis
from redis import Redis

def test_redis():
    fake_redis = FakeRedis()
    real_redis = Redis(host="localhost", port=6379)

    fake_redis.xadd("test", {"x": 1})
    real_redis.xadd("test", {"x": 1})

    res1 = fake_redis.xread(streams={"test": "0"}, count=100, block=10)
    res2 = real_redis.xread(streams={"test": "0"}, count=100, block=10)
    assert len(res1) == len(res2)
sveta-afanaseva commented 11 months ago

Oh, sorry, it returns empty list, not None. My mistake

cunla commented 11 months ago

Ok, I wrote a test that is able to replicate it. I'll try to fix it this weekend.