Commit 973cb21a authored by antirez's avatar antirez
Browse files

Invert two sides of if expression in SET to avoid a lookup.

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.
parent b16e4234
...@@ -26,7 +26,7 @@ void setGenericCommand(redisClient *c, int nx, robj *key, robj *val, robj *expir ...@@ -26,7 +26,7 @@ void setGenericCommand(redisClient *c, int nx, robj *key, robj *val, robj *expir
if (unit == UNIT_SECONDS) milliseconds *= 1000; if (unit == UNIT_SECONDS) milliseconds *= 1000;
} }
if (lookupKeyWrite(c->db,key) != NULL && nx) { if (nx && lookupKeyWrite(c->db,key) != NULL) {
addReply(c,shared.czero); addReply(c,shared.czero);
return; return;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment