{"action":"opened","issue":{"url":"https://api.github.com/repos/jamesls/fakeredis/issues/135","repository_url":"https://api.github.com/repos/jamesls/fakeredis","labels_url":"https://api.github.com/repos/jamesls/fakeredis/issues/135/labels{/name}","comments_url":"https://api.github.com/repos/jamesls/fakeredis/issues/135/comments","events_url":"https://api.github.com/repos/jamesls/fakeredis/issues/135/events","html_url":"https://github.com/jamesls/fakeredis/issues/135","id":195414472,"number":135,"title":"Scan includes expired keys","user":{"login":"tommikaikkonen","id":2487359,"avatar_url":"https://avatars.githubusercontent.com/u/2487359?v=3","gravatar_id":"","url":"https://api.github.com/users/tommikaikkonen","html_url":"https://github.com/tommikaikkonen","followers_url":"https://api.github.com/users/tommikaikkonen/followers","following_url":"https://api.github.com/users/tommikaikkonen/following{/other_user}","gists_url":"https://api.github.com/users/tommikaikkonen/gists{/gist_id}","starred_url":"https://api.github.com/users/tommikaikkonen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tommikaikkonen/subscriptions","organizations_url":"https://api.github.com/users/tommikaikkonen/orgs","repos_url":"https://api.github.com/users/tommikaikkonen/repos","events_url":"https://api.github.com/users/tommikaikkonen/events{/privacy}","received_events_url":"https://api.github.com/users/tommikaikkonen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-14T01:11:15Z","updated_at":"2016-12-14T01:11:15Z","closed_at":null,"body":"I'm not sure if this is the desired functionality, but using `scan` and `scan_iter` includes expired keys.\r\n\r\nHere is how to reproduce (just save to file and run with python3)\r\n\r\n```python\r\nfrom fakeredis import FakeStrictRedis\r\nfrom time import sleep\r\n\r\n\r\ndef main():\r\n    redis = FakeStrictRedis()\r\n    redis.set('expiringkey', 'value')\r\n    redis.expire('expiringkey', 0)\r\n\r\n    sleep(1)\r\n\r\n    keys = list(redis.scan_iter())\r\n    print(keys)  # prints [b'expiringkey'], expected []\r\n\r\n\r\nif __name__ == '__main__':\r\n    main()\r\n\r\n```\r\n\r\nLooks like the culprit is [the `__iter__` implementation of `_StrKeyDict`](https://github.com/jamesls/fakeredis/blob/master/fakeredis.py#L127), 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.\r\n\r\nIf this is indeed a bug and my solution sounds good, I can submit a PR."}}
{"actor":{"display_login":"tommikaikkonen"}}