-
Notifications
You must be signed in to change notification settings - Fork 180
Closed
Labels
Description
I'm not sure if this is the desired functionality, but using scan and scan_iter includes expired keys.
Here is how to reproduce (just save to file and run with python3)
from fakeredis import FakeStrictRedis
from time import sleep
def main():
redis = FakeStrictRedis()
redis.set('expiringkey', 'value')
redis.expire('expiringkey', 0)
sleep(1)
keys = list(redis.scan_iter())
print(keys) # prints [b'expiringkey'], expected []
if __name__ == '__main__':
main()Looks like the culprit is the __iter__ implementation of _StrKeyDict, which doesn't call self._update_expired_keys() like __getitem__ does. I suppose it should be called before returning the iterator, resulting in keys being expired at the start of each scan call.
If this is indeed a bug and my solution sounds good, I can submit a PR.
joshp123