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

Scan includes expired keys #135

Closed
tommikaikkonen opened this issue Dec 14, 2016 · 1 comment
Closed

Scan includes expired keys #135

tommikaikkonen opened this issue Dec 14, 2016 · 1 comment

Comments

@tommikaikkonen
Copy link

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.

@bmerry
Copy link
Collaborator

bmerry commented Mar 23, 2018

I think your analysis is correct. The implementation has changed quite a bit, but the issue still remains, and could be fixed by overriding keys to filter out expired keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants