sds / mock_redis

Mock Redis gem for Ruby
Other
489 stars 153 forks source link

SCAN fails if keys are deleted in the iteration #193

Closed arvid220u closed 7 months ago

arvid220u commented 4 years ago

The following minimal example showcases a discrepancy between MockRedis and the real Redis.

First, let's add two keys:

mock_redis = MockRedis.new
mock_redis.set("key1", "value1")
mock_redis.set("key2", "value2")

Second, let's scan:

mock_redis.scan("0", count: 1)
=> ["1", ["key1"]]

This is the expected return value. Now, let's say we want to remove key1 and continue our scan:

mock_redis.del("key1")
mock_redis.scan("1", count: 1)
=> ["0", []]

This is where the bug is, because we expect to receive back ["0", ["key2"]], which is what the real Redis gives us.

I looked into the implementation of scan in MockRedis and it looks like it behaves quite differently from scan in the real Redis, so I'm not sure how to fix it.

I know that scan is not listed under the supported features of MockRedis, so I totally understand if this is a non-fix. In that case, maybe scan should be listed under "Mostly-Supported Commands" of the Readme?

sds commented 4 years ago

@alfonsojimenez implemented this long ago (thank you!)

Would love to see a pull request resolving the functional discrepancy—but otherwise agree a documentation change would help clarify.

sds commented 7 months ago

Open to pull requests addressing this.