Skip to content

Commit

Permalink
Optimize the performance of msetnx command by call lookupkey only once (
Browse files Browse the repository at this point in the history
#11594)

This is a small addition to #9640
It improves performance by avoiding double lookup of the the key.
  • Loading branch information
judeng committed Jan 3, 2023
1 parent d2d6bc1 commit 884ca60
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/t_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ void mgetCommand(client *c) {

void msetGenericCommand(client *c, int nx) {
int j;
int setkey_flags = 0;

if ((c->argc % 2) == 0) {
addReplyErrorArity(c);
Expand All @@ -568,11 +569,12 @@ void msetGenericCommand(client *c, int nx) {
return;
}
}
setkey_flags |= SETKEY_DOESNT_EXIST;
}

for (j = 1; j < c->argc; j += 2) {
c->argv[j+1] = tryObjectEncoding(c->argv[j+1]);
setKey(c,c->db,c->argv[j],c->argv[j+1],0);
setKey(c, c->db, c->argv[j], c->argv[j + 1], setkey_flags);
notifyKeyspaceEvent(NOTIFY_STRING,"set",c->argv[j],c->db->id);
}
server.dirty += (c->argc-1)/2;
Expand Down

0 comments on commit 884ca60

Please sign in to comment.