Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix infinite loop by randomkey if the slave only has expired key.

 - count retry and return key if it reach dbSize
  • Loading branch information...
commit cca397808888945812137713ddc944db0058a52f 1 parent c1234e4
Minsu Choi authored
Showing with 5 additions and 3 deletions.
  1. +5 −3 src/db.c
View
8 src/db.c
@@ -145,15 +145,17 @@ robj *dbRandomKey(redisDb *db) {
de = dictGetRandomKey(db->dict);
if (de == NULL) return NULL;
+ unsigned long retry = dictSize(db->dict);
key = dictGetKey(de);
keyobj = createStringObject(key,sdslen(key));
if (dictFind(db->expires,key)) {
if (expireIfNeeded(db,keyobj)) {
decrRefCount(keyobj);
- /* Escaping from infinite loop by RANDOMKEY if slave has only expired key. */
- if (server.masterhost != NULL && dictSize(db->dict) == dictSize(db->expires)) {
- return NULL;
+ /* Escaping from loop by retry count although it expired */
+ if (retry <= 0) {
+ return keyobj;
}
+ retry--;
continue; /* search for another key. This expired. */
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.