Avoid unnecessary slot computing in KEYS command. (#12843)

If not in cluster mode, there is no need to compute slot.

A bit optimization for #12754
This commit is contained in:
Chen Tianjie 2023-12-07 19:48:15 +08:00 committed by GitHub
parent 8e11f84ded
commit f2d59c4f91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1003,12 +1003,12 @@ void keysCommand(client *c) {
long numkeys = 0;
void *replylen = addReplyDeferredLen(c);
allkeys = (pattern[0] == '*' && plen == 1);
if (!allkeys) {
if (server.cluster_enabled && !allkeys) {
pslot = patternHashSlot(pattern, plen);
}
dictIterator *di = NULL;
dbIterator *dbit = NULL;
if (server.cluster_enabled && !allkeys && pslot != -1) {
if (pslot != -1) {
di = dictGetSafeIterator(c->db->dict[pslot]);
} else {
dbit = dbIteratorInit(c->db, DB_MAIN);