mirror of
https://github.com/fluencelabs/redis
synced 2025-03-17 16:10:50 +00:00
Variadic SREM
This commit is contained in:
parent
64a13a36e6
commit
b3a96d454e
@ -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},
|
||||
{"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},
|
||||
|
19
src/t_set.c
19
src/t_set.c
@ -242,19 +242,22 @@ void saddCommand(redisClient *c) {
|
||||
|
||||
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]);
|
||||
signalModifiedKey(c->db,c->argv[1]);
|
||||
server.dirty++;
|
||||
addReply(c,shared.cone);
|
||||
} else {
|
||||
addReply(c,shared.czero);
|
||||
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 += deleted;
|
||||
}
|
||||
addReplyLongLong(c,deleted);
|
||||
}
|
||||
|
||||
void smoveCommand(redisClient *c) {
|
||||
|
@ -97,6 +97,14 @@ start_server {
|
||||
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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user