SETNX and MSETNX now respect the delete-on-write operation of EXPIREing keys

This commit is contained in:
antirez 2009-12-06 01:09:15 +01:00
parent 71c54b21e2
commit 906573e78d

12
redis.c
View File

@ -2978,6 +2978,7 @@ static void echoCommand(redisClient *c) {
static void setGenericCommand(redisClient *c, int nx) { static void setGenericCommand(redisClient *c, int nx) {
int retval; int retval;
lookupKeyWrite(c->db,c->argv[1]);
retval = dictAdd(c->db->dict,c->argv[1],c->argv[2]); retval = dictAdd(c->db->dict,c->argv[1],c->argv[2]);
if (retval == DICT_ERR) { if (retval == DICT_ERR) {
if (!nx) { if (!nx) {
@ -3053,7 +3054,7 @@ static void mgetCommand(redisClient *c) {
} }
static void msetGenericCommand(redisClient *c, int nx) { static void msetGenericCommand(redisClient *c, int nx) {
int j; int j, busykeys = 0;
if ((c->argc % 2) == 0) { if ((c->argc % 2) == 0) {
addReplySds(c,sdsnew("-ERR wrong number of arguments\r\n")); addReplySds(c,sdsnew("-ERR wrong number of arguments\r\n"));
@ -3063,12 +3064,15 @@ static void msetGenericCommand(redisClient *c, int nx) {
* set nothing at all if at least one already key exists. */ * set nothing at all if at least one already key exists. */
if (nx) { if (nx) {
for (j = 1; j < c->argc; j += 2) { for (j = 1; j < c->argc; j += 2) {
if (dictFind(c->db->dict,c->argv[j]) != NULL) { if (lookupKeyWrite(c->db,c->argv[j]) != NULL) {
addReply(c, shared.czero); busykeys++;
return;
} }
} }
} }
if (busykeys) {
addReply(c, shared.czero);
return;
}
for (j = 1; j < c->argc; j += 2) { for (j = 1; j < c->argc; j += 2) {
int retval; int retval;