summaryrefslogtreecommitdiff
path: root/src/t_zset.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2011-05-31 20:15:18 +0200
committerantirez <antirez@gmail.com>2011-05-31 20:15:18 +0200
commit3f7b2b1f300e6d0441f420fcb51c253b10631cfa (patch)
treea01e4b33cd8a77a814877a2594ac95ed639fd92f /src/t_zset.c
parent3738ff5f32aaadd3074a691544caf2f2daa77928 (diff)
downloadredis-3f7b2b1f300e6d0441f420fcb51c253b10631cfa.tar.gz
Variadic ZREM
Diffstat (limited to 'src/t_zset.c')
-rw-r--r--src/t_zset.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/src/t_zset.c b/src/t_zset.c
index a0c1b1e89..6a56c3b4e 100644
--- a/src/t_zset.c
+++ b/src/t_zset.c
@@ -957,8 +957,8 @@ void zincrbyCommand(redisClient *c) {
void zremCommand(redisClient *c) {
robj *key = c->argv[1];
- robj *ele = c->argv[2];
robj *zobj;
+ int deleted = 0, j;
if ((zobj = lookupKeyWriteOrReply(c,key,shared.czero)) == NULL ||
checkType(c,zobj,REDIS_ZSET)) return;
@@ -966,39 +966,48 @@ void zremCommand(redisClient *c) {
if (zobj->encoding == REDIS_ENCODING_ZIPLIST) {
unsigned char *eptr;
- if ((eptr = zzlFind(zobj->ptr,ele,NULL)) != NULL) {
- zobj->ptr = zzlDelete(zobj->ptr,eptr);
- if (zzlLength(zobj->ptr) == 0) dbDelete(c->db,key);
- } else {
- addReply(c,shared.czero);
- return;
+ for (j = 2; j < c->argc; j++) {
+ if ((eptr = zzlFind(zobj->ptr,c->argv[j],NULL)) != NULL) {
+ deleted++;
+ zobj->ptr = zzlDelete(zobj->ptr,eptr);
+ if (zzlLength(zobj->ptr) == 0) {
+ dbDelete(c->db,key);
+ break;
+ }
+ }
}
} else if (zobj->encoding == REDIS_ENCODING_SKIPLIST) {
zset *zs = zobj->ptr;
dictEntry *de;
double score;
- de = dictFind(zs->dict,ele);
- if (de != NULL) {
- /* Delete from the skiplist */
- score = *(double*)dictGetEntryVal(de);
- redisAssert(zslDelete(zs->zsl,score,ele));
-
- /* Delete from the hash table */
- dictDelete(zs->dict,ele);
- if (htNeedsResize(zs->dict)) dictResize(zs->dict);
- if (dictSize(zs->dict) == 0) dbDelete(c->db,key);
- } else {
- addReply(c,shared.czero);
- return;
+ for (j = 2; j < c->argc; j++) {
+ de = dictFind(zs->dict,c->argv[j]);
+ if (de != NULL) {
+ deleted++;
+
+ /* Delete from the skiplist */
+ score = *(double*)dictGetEntryVal(de);
+ redisAssert(zslDelete(zs->zsl,score,c->argv[j]));
+
+ /* Delete from the hash table */
+ dictDelete(zs->dict,c->argv[j]);
+ if (htNeedsResize(zs->dict)) dictResize(zs->dict);
+ if (dictSize(zs->dict) == 0) {
+ dbDelete(c->db,key);
+ break;
+ }
+ }
}
} else {
redisPanic("Unknown sorted set encoding");
}
- signalModifiedKey(c->db,key);
- server.dirty++;
- addReply(c,shared.cone);
+ if (deleted) {
+ signalModifiedKey(c->db,key);
+ server.dirty += deleted;
+ }
+ addReplyLongLong(c,deleted);
}
void zremrangebyscoreCommand(redisClient *c) {