]> git.saurik.com Git - redis.git/commitdiff
Variadic SREM
authorantirez <antirez@gmail.com>
Tue, 19 Apr 2011 15:37:03 +0000 (17:37 +0200)
committerantirez <antirez@gmail.com>
Tue, 19 Apr 2011 15:37:03 +0000 (17:37 +0200)
src/redis.c
src/t_set.c
tests/unit/type/set.tcl

index bf9ced2cd0a3b30f06ad19c569c2d1a47cb435a5..1ac95702bfe72c5f361fe663526606d7f49bf0d8 100644 (file)
@@ -103,7 +103,7 @@ struct redisCommand redisCommandTable[] = {
     {"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},
     {"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},
     {"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},
index 138a2f8de28888d7c853be841f5b83221701a8db..b221e2e99cd129f7e385f00fc3783931bc97181b 100644 (file)
@@ -242,19 +242,22 @@ void saddCommand(redisClient *c) {
 
 void sremCommand(redisClient *c) {
     robj *set;
 
 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;
 
 
     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]);
         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) {
 }
 
 void smoveCommand(redisClient *c) {
index ef7d668cc2f0b9750731e590d7ea52d95cabb20d..1a37ed616ae48648996f80722f1e22bf2237b5aa 100644 (file)
@@ -97,6 +97,14 @@ start_server {
         assert_equal {3 5} [lsort [r smembers myset]]
     }
 
         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]
     foreach {type} {hashtable intset} {
         for {set i 1} {$i <= 5} {incr i} {
             r del [format "set%d" $i]