From 9311d2b527b0bb3e72e61b143718e6def51491e6 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Mon, 30 Apr 2012 10:16:20 -0700 Subject: [PATCH] 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. --- src/db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db.c b/src/db.c index 3c75f6ba..e65106a5 100644 --- a/src/db.c +++ b/src/db.c @@ -255,7 +255,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 = dictGetKey(de); -- 2.45.2