Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
913090ec
Commit
913090ec
authored
May 31, 2011
by
antirez
Browse files
Variadic ZREM
parent
51501514
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/redis.c
View file @
913090ec
...
@@ -118,7 +118,7 @@ struct redisCommand readonlyCommandTable[] = {
...
@@ -118,7 +118,7 @@ struct redisCommand readonlyCommandTable[] = {
{"smembers",sinterCommand,2,0,NULL,1,1,1},
{"smembers",sinterCommand,2,0,NULL,1,1,1},
{"zadd",zaddCommand,4,REDIS_CMD_DENYOOM,NULL,1,1,1},
{"zadd",zaddCommand,4,REDIS_CMD_DENYOOM,NULL,1,1,1},
{"zincrby",zincrbyCommand,4,REDIS_CMD_DENYOOM,NULL,1,1,1},
{"zincrby",zincrbyCommand,4,REDIS_CMD_DENYOOM,NULL,1,1,1},
{"zrem",zremCommand,3,0,NULL,1,1,1},
{"zrem",zremCommand,
-
3,0,NULL,1,1,1},
{"zremrangebyscore",zremrangebyscoreCommand,4,0,NULL,1,1,1},
{"zremrangebyscore",zremrangebyscoreCommand,4,0,NULL,1,1,1},
{"zremrangebyrank",zremrangebyrankCommand,4,0,NULL,1,1,1},
{"zremrangebyrank",zremrangebyrankCommand,4,0,NULL,1,1,1},
{"zunionstore",zunionstoreCommand,-4,REDIS_CMD_DENYOOM,zunionInterBlockClientOnSwappedKeys,0,0,0},
{"zunionstore",zunionstoreCommand,-4,REDIS_CMD_DENYOOM,zunionInterBlockClientOnSwappedKeys,0,0,0},
...
...
src/t_zset.c
View file @
913090ec
...
@@ -951,8 +951,8 @@ void zincrbyCommand(redisClient *c) {
...
@@ -951,8 +951,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;
...
@@ -960,39 +960,48 @@ void zremCommand(redisClient *c) {
...
@@ -960,39 +960,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 skiplist */
/* Delete from the hash table */
score = *(double*)dictGetEntryVal(de);
dictDelete
(
zs
->
dict
,
ele
);
redisAssert(zslDelete(zs->zsl,score,c->argv[j]));
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
if
(
dictSize
(
zs
->
dict
)
==
0
)
dbDelete
(
c
->
db
,
key
);
/* Delete from the hash table */
}
else
{
dictDelete(zs->dict,c->argv[j]);
addReply
(
c
,
shared
.
czero
);
if (htNeedsResize(zs->dict)) dictResize(zs->dict);
return
;
if (dictSize(zs->dict) == 0) {
dbDelete(c->db,key);
break;
}
}
}
}
} else {
} else {
redisPanic("Unknown sorted set encoding");
redisPanic("Unknown sorted set encoding");
}
}
touchWatchedKey
(
c
->
db
,
key
);
if (deleted) {
server
.
dirty
++
;
touchWatchedKey(c->db,key);
addReply
(
c
,
shared
.
cone
);
server.dirty += deleted;
}
addReplyLongLong(c,deleted);
}
}
void zremrangebyscoreCommand(redisClient *c) {
void zremrangebyscoreCommand(redisClient *c) {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment