cunla / fakeredis-py

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

TTL returns -2 (not found) for empty streams #313

Closed Eugeny closed 5 months ago

Eugeny commented 5 months ago

STR:

fake_redis.xadd(self.stream_name, {'x': 1})
fake_redis.expire(self.stream_name, 60 * 60 * 24 * 365 * 99)
assert fake_redis.keys(self.stream_name) 
fake_redis.ttl(self.stream_name) # is -2

Python 3.10 redis-py==4.5.4 fakeredis==2.23.2

Upvote & Fund

Fund with Polar

Eugeny commented 5 months ago

Upon further investigation this is due to if (not key...) return in _expireat, whose __bool__ then checks for bool(self._value) which is False because XStream.__len__ is 0

cunla commented 5 months ago

Thanks for reporting this. Do you want to work on a fix and submit a PR (since you already did the hard part)?

Otherwise, I will work on it this weekend;

Eugeny commented 5 months ago

I'm not actually sure what the purpose of the if not key check in _expireat is so I would prefer not to risk breaking anything by not knowing the library, I literally just started using it today :D

cunla commented 5 months ago

No prob, I'll have a look at it later this week. Thanks again for reporting

cunla commented 5 months ago

fixed

Eugeny commented 5 months ago

Thank you!