diff --git a/src/db.c b/src/db.c index ddfb04ebb..31c8f69bd 100644 --- a/src/db.c +++ b/src/db.c @@ -774,17 +774,16 @@ void keysCommand(client *c) { di = dictGetSafeIterator(c->db->dict); allkeys = (pattern[0] == '*' && plen == 1); + robj keyobj; while((de = dictNext(di)) != NULL) { sds key = dictGetKey(de); - robj *keyobj; if (allkeys || stringmatchlen(pattern,plen,key,sdslen(key),0)) { - keyobj = createStringObject(key,sdslen(key)); - if (!keyIsExpired(c->db,keyobj)) { - addReplyBulk(c,keyobj); + initStaticStringObject(keyobj, key); + if (!keyIsExpired(c->db, &keyobj)) { + addReplyBulkCBuffer(c, key, sdslen(key)); numkeys++; } - decrRefCount(keyobj); } if (c->flags & CLIENT_CLOSE_ASAP) break;