mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
improve performance of keys command by using static objects (#12036)
Improve performance by avoiding redundancy memory malloc/free
This commit is contained in:
parent
d5d56d0d95
commit
1222b60873
9
src/db.c
9
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;
|
||||
|
Loading…
Reference in New Issue
Block a user