Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Use safe dictionary iterator from KEYS

Every matched key in a KEYS call is checked for expiration. When the key
is set to expire, the call to `getExpire` will assert that the key also
exists in the main dictionary. This in turn causes a rehashing step to
be executed. Rehashing a dictionary when there is an iterator active may
result in the iterator emitting duplicate entries, or not emitting some
entries at all. By using a safe iterator, the rehash step is omitted.
  • Loading branch information...
1 parent 9cb09c4 commit f2ffb592947407a54e4a1f915f1593aa84eb2295 @pietern pietern committed with
Showing with 1 addition and 1 deletion.
  1. +1 −1  src/db.c
2  src/db.c
@@ -273,7 +273,7 @@ void keysCommand(redisClient *c) {
unsigned long numkeys = 0;
void *replylen = addDeferredMultiBulkLength(c);
- di = dictGetIterator(c->db->dict);
+ di = dictGetSafeIterator(c->db->dict);
allkeys = (pattern[0] == '*' && pattern[1] == '\0');
while((de = dictNext(di)) != NULL) {
sds key = dictGetEntryKey(de);

0 comments on commit f2ffb59

Please sign in to comment.
Something went wrong with that request. Please try again.