Variadic ZREM
This commit is contained in:
parent
3738ff5f32
commit
3f7b2b1f30
@ -118,7 +118,7 @@ struct redisCommand redisCommandTable[] = {
|
|||||||
{"smembers",sinterCommand,2,0,NULL,1,1,1,0,0},
|
{"smembers",sinterCommand,2,0,NULL,1,1,1,0,0},
|
||||||
{"zadd",zaddCommand,-4,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
|
{"zadd",zaddCommand,-4,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
|
||||||
{"zincrby",zincrbyCommand,4,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
|
{"zincrby",zincrbyCommand,4,REDIS_CMD_DENYOOM,NULL,1,1,1,0,0},
|
||||||
{"zrem",zremCommand,3,0,NULL,1,1,1,0,0},
|
{"zrem",zremCommand,-3,0,NULL,1,1,1,0,0},
|
||||||
{"zremrangebyscore",zremrangebyscoreCommand,4,0,NULL,1,1,1,0,0},
|
{"zremrangebyscore",zremrangebyscoreCommand,4,0,NULL,1,1,1,0,0},
|
||||||
{"zremrangebyrank",zremrangebyrankCommand,4,0,NULL,1,1,1,0,0},
|
{"zremrangebyrank",zremrangebyrankCommand,4,0,NULL,1,1,1,0,0},
|
||||||
{"zunionstore",zunionstoreCommand,-4,REDIS_CMD_DENYOOM,zunionInterGetKeys,0,0,0,0,0},
|
{"zunionstore",zunionstoreCommand,-4,REDIS_CMD_DENYOOM,zunionInterGetKeys,0,0,0,0,0},
|
||||||
|
53
src/t_zset.c
53
src/t_zset.c
@ -957,8 +957,8 @@ void zincrbyCommand(redisClient *c) {
|
|||||||
|
|
||||||
void zremCommand(redisClient *c) {
|
void zremCommand(redisClient *c) {
|
||||||
robj *key = c->argv[1];
|
robj *key = c->argv[1];
|
||||||
robj *ele = c->argv[2];
|
|
||||||
robj *zobj;
|
robj *zobj;
|
||||||
|
int deleted = 0, j;
|
||||||
|
|
||||||
if ((zobj = lookupKeyWriteOrReply(c,key,shared.czero)) == NULL ||
|
if ((zobj = lookupKeyWriteOrReply(c,key,shared.czero)) == NULL ||
|
||||||
checkType(c,zobj,REDIS_ZSET)) return;
|
checkType(c,zobj,REDIS_ZSET)) return;
|
||||||
@ -966,39 +966,48 @@ void zremCommand(redisClient *c) {
|
|||||||
if (zobj->encoding == REDIS_ENCODING_ZIPLIST) {
|
if (zobj->encoding == REDIS_ENCODING_ZIPLIST) {
|
||||||
unsigned char *eptr;
|
unsigned char *eptr;
|
||||||
|
|
||||||
if ((eptr = zzlFind(zobj->ptr,ele,NULL)) != NULL) {
|
for (j = 2; j < c->argc; j++) {
|
||||||
zobj->ptr = zzlDelete(zobj->ptr,eptr);
|
if ((eptr = zzlFind(zobj->ptr,c->argv[j],NULL)) != NULL) {
|
||||||
if (zzlLength(zobj->ptr) == 0) dbDelete(c->db,key);
|
deleted++;
|
||||||
} else {
|
zobj->ptr = zzlDelete(zobj->ptr,eptr);
|
||||||
addReply(c,shared.czero);
|
if (zzlLength(zobj->ptr) == 0) {
|
||||||
return;
|
dbDelete(c->db,key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (zobj->encoding == REDIS_ENCODING_SKIPLIST) {
|
} else if (zobj->encoding == REDIS_ENCODING_SKIPLIST) {
|
||||||
zset *zs = zobj->ptr;
|
zset *zs = zobj->ptr;
|
||||||
dictEntry *de;
|
dictEntry *de;
|
||||||
double score;
|
double score;
|
||||||
|
|
||||||
de = dictFind(zs->dict,ele);
|
for (j = 2; j < c->argc; j++) {
|
||||||
if (de != NULL) {
|
de = dictFind(zs->dict,c->argv[j]);
|
||||||
/* Delete from the skiplist */
|
if (de != NULL) {
|
||||||
score = *(double*)dictGetEntryVal(de);
|
deleted++;
|
||||||
redisAssert(zslDelete(zs->zsl,score,ele));
|
|
||||||
|
|
||||||
/* Delete from the hash table */
|
/* Delete from the skiplist */
|
||||||
dictDelete(zs->dict,ele);
|
score = *(double*)dictGetEntryVal(de);
|
||||||
if (htNeedsResize(zs->dict)) dictResize(zs->dict);
|
redisAssert(zslDelete(zs->zsl,score,c->argv[j]));
|
||||||
if (dictSize(zs->dict) == 0) dbDelete(c->db,key);
|
|
||||||
} else {
|
/* Delete from the hash table */
|
||||||
addReply(c,shared.czero);
|
dictDelete(zs->dict,c->argv[j]);
|
||||||
return;
|
if (htNeedsResize(zs->dict)) dictResize(zs->dict);
|
||||||
|
if (dictSize(zs->dict) == 0) {
|
||||||
|
dbDelete(c->db,key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
redisPanic("Unknown sorted set encoding");
|
redisPanic("Unknown sorted set encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
signalModifiedKey(c->db,key);
|
if (deleted) {
|
||||||
server.dirty++;
|
signalModifiedKey(c->db,key);
|
||||||
addReply(c,shared.cone);
|
server.dirty += deleted;
|
||||||
|
}
|
||||||
|
addReplyLongLong(c,deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void zremrangebyscoreCommand(redisClient *c) {
|
void zremrangebyscoreCommand(redisClient *c) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user