mirror of
https://github.com/fluencelabs/redis
synced 2025-05-05 07:22:15 +00:00
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.
This commit is contained in:
parent
2ac546e00c
commit
cc4f65fea4
2
src/db.c
2
src/db.c
@ -261,7 +261,7 @@ void keysCommand(redisClient *c) {
|
|||||||
unsigned long numkeys = 0;
|
unsigned long numkeys = 0;
|
||||||
void *replylen = addDeferredMultiBulkLength(c);
|
void *replylen = addDeferredMultiBulkLength(c);
|
||||||
|
|
||||||
di = dictGetIterator(c->db->dict);
|
di = dictGetSafeIterator(c->db->dict);
|
||||||
allkeys = (pattern[0] == '*' && pattern[1] == '\0');
|
allkeys = (pattern[0] == '*' && pattern[1] == '\0');
|
||||||
while((de = dictNext(di)) != NULL) {
|
while((de = dictNext(di)) != NULL) {
|
||||||
sds key = dictGetKey(de);
|
sds key = dictGetKey(de);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user