Chris Gonzalez
Chris Gonzalez

Reputation: 123

Is it safe to delete keys from Redis while iterating through them using scan?

I want to iterate through a number of keys that are stored in Redis with the same prefix using scan and do some processing in my app code with the key's values. Is it safe to delete the keys returned from scan's output after processing them? I don't see this mentioned in the scan documentation: https://redis.io/commands/scan

Upvotes: 1

Views: 776

Answers (1)

for_stack
for_stack

Reputation: 22906

Yes, it's safe to delete the returned keys.

Redis scan is stateless. Keyspace change (e.g. adding new keys or removing old keys) during the scan process does not make the scan fail, although Keyspace change might lead to keys missing or duplicated keys returned.

Check this on the details of how Redis scan work.

Upvotes: 3

Related Questions