{"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},
- {"srem",sremCommand,3,0,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},
{"scard",scardCommand,2,0,NULL,1,1,1,0,0},
void sremCommand(redisClient *c) {
robj *set;
+ int j, deleted = 0;
if ((set = lookupKeyWriteOrReply(c,c->argv[1],shared.czero)) == NULL ||
checkType(c,set,REDIS_SET)) return;
- c->argv[2] = tryObjectEncoding(c->argv[2]);
- if (setTypeRemove(set,c->argv[2])) {
- if (setTypeSize(set) == 0) dbDelete(c->db,c->argv[1]);
+ for (j = 2; j < c->argc; j++) {
+ if (setTypeRemove(set,c->argv[j])) {
+ if (setTypeSize(set) == 0) dbDelete(c->db,c->argv[1]);
+ deleted++;
+ }
+ }
+ if (deleted) {
signalModifiedKey(c->db,c->argv[1]);
- server.dirty++;
- addReply(c,shared.cone);
- } else {
- addReply(c,shared.czero);
+ server.dirty += deleted;
}
+ addReplyLongLong(c,deleted);
}
void smoveCommand(redisClient *c) {
assert_equal {3 5} [lsort [r smembers myset]]
}
+ test {SREM with multiple arguments} {
+ r del myset
+ r sadd myset a b c d
+ assert_equal 0 [r srem myset k k k]
+ assert_equal 2 [r srem myset b d x y]
+ lsort [r smembers myset]
+ } {a c}
+
foreach {type} {hashtable intset} {
for {set i 1} {$i <= 5} {incr i} {
r del [format "set%d" $i]