Skip to content

Commit

Permalink
Invert two sides of if expression in SET to avoid a lookup.
Browse files Browse the repository at this point in the history
Because of the short circuit behavior of && inverting the two sides of
the if expression avoids an hash table lookup if the non-EX variant of
SET is called.

Thanks to Weibin Yao (@yaoweibin on github) for spotting this.
  • Loading branch information
antirez committed Oct 31, 2012
1 parent 5bf0997 commit 4d9bd53
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/t_string.c
Expand Up @@ -26,7 +26,7 @@ void setGenericCommand(redisClient *c, int nx, robj *key, robj *val, robj *expir
if (unit == UNIT_SECONDS) milliseconds *= 1000;
}

if (lookupKeyWrite(c->db,key) != NULL && nx) {
if (nx && lookupKeyWrite(c->db,key) != NULL) {
addReply(c,shared.czero);
return;
}
Expand Down

0 comments on commit 4d9bd53

Please sign in to comment.