From: antirez Date: Fri, 15 Apr 2011 16:08:32 +0000 (+0200) Subject: variadic SADD X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/22f294d24a1d56a655bdca69184e048e3ef49934 variadic SADD --- diff --git a/src/redis.c b/src/redis.c index 38e4ce52..5f07903c 100644 --- a/src/redis.c +++ b/src/redis.c @@ -102,7 +102,7 @@ struct redisCommand redisCommandTable[] = { {"ltrim",ltrimCommand,4,0,NULL,1,1,1,0,0}, {"lrem",lremCommand,4,0,NULL,1,1,1,0,0}, {"rpoplpush",rpoplpushCommand,3,REDIS_CMD_DENYOOM,NULL,1,2,1,0,0}, - {"sadd",saddCommand,3,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0}, + {"sadd",saddCommand,-3,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0}, {"srem",sremCommand,3,0,NULL,1,1,1,0,0}, {"smove",smoveCommand,4,0,NULL,1,2,1,0,0}, {"sismember",sismemberCommand,3,0,NULL,1,1,1,0,0}, diff --git a/src/t_set.c b/src/t_set.c index 7d0811ed..138a2f8d 100644 --- a/src/t_set.c +++ b/src/t_set.c @@ -218,9 +218,9 @@ void setTypeConvert(robj *setobj, int enc) { void saddCommand(redisClient *c) { robj *set; + int j, added = 0; set = lookupKeyWrite(c->db,c->argv[1]); - c->argv[2] = tryObjectEncoding(c->argv[2]); if (set == NULL) { set = setTypeCreate(c->argv[2]); dbAdd(c->db,c->argv[1],set); @@ -230,13 +230,14 @@ void saddCommand(redisClient *c) { return; } } - if (setTypeAdd(set,c->argv[2])) { - signalModifiedKey(c->db,c->argv[1]); - server.dirty++; - addReply(c,shared.cone); - } else { - addReply(c,shared.czero); + + for (j = 2; j < c->argc; j++) { + c->argv[j] = tryObjectEncoding(c->argv[j]); + if (setTypeAdd(set,c->argv[j])) added++; } + if (added) signalModifiedKey(c->db,c->argv[1]); + server.dirty += added; + addReplyLongLong(c,added); } void sremCommand(redisClient *c) {