improve performance of keys command by using static objects (#12036)

Improve performance by avoiding redundancy memory malloc/free
This commit is contained in:
judeng 2023-04-16 18:02:47 +08:00 committed by GitHub
parent d5d56d0d95
commit 1222b60873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;