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
281 stars 47 forks source link

xinfo_stream returns data for a stream that doesn't exist #296

Closed steve-mavens closed 6 months ago

steve-mavens commented 6 months ago

Describe the bug

This is a difference between fakeredis and real redis. On real redis if you call xinfo_stream for a stream name that doesn't exist, you get an exception. On fakeredis you get back dummy data.

To Reproduce

import fakeredis
import redis

def main() -> None:
    fake = fakeredis.FakeRedis(version=6)
    assert fake.keys("*exist*") == []
    print('fakeredis returns', fake.xinfo_stream("nonexistent"))
    assert fake.keys("*exist*") == []

    real = redis.Redis("localhost")
    assert real.keys("*exist*") == []
    print('real redis returns', real.xinfo_stream("nonexistent"))

if __name__ == "__main__":
    main()

Result is:

fakeredis returns {'length': 0, 'groups': 0, 'first-entry': None, 'last-entry': None, 'max-deleted-entry-id': b'0-0', 'entries-added': 0, 'recorded-first-entry-id': b'0-0'}
Traceback (most recent call last):
  File "fakeredis_xinfo_test.py", line 17, in <module>
    main()
  File "fakeredis_xinfo_test.py", line 13, in main
    print('real redis returns', real.xinfo_stream("nonexistent"))
  <snip the rest of the stack trace>
redis.exceptions.ResponseError: no such key

Expected behavior

fakeredis raises exception to match real redis's behaviour

Desktop (please complete the following information):

Upvote & Fund

Fund with Polar

steve-mavens commented 6 months ago

My actual code uses redis.asyncio.Redis (and fakeredis.aioredis.FakeRedis for testing) and has the same issue, but I wrote the minimal demonstration code using the synchronous client to see whether async was anything to do with it. Doesn't seem to be!