Skip to content

Commit

Permalink
ZREM implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Oct 26, 2009
1 parent f4d4c47 commit 1b7106e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Pre 1.1 todo
* For now only the last argument gets integer encoded, so make sure that: 1) every multi bulk commands implemented will have the last arg that is indeed a value, and not used otherwise. 2) to explicitly call the function to encode the object in MSET and other commands where there are multiple "values".
* Man pages for MSET MSETNX and SRANDMEMBER.
* Hashes (HSET, HGET, HEXISTS, HLEN, ...).
* ZSETs
* ZSETs: ZADD, ZRANGE, ZDEL, ZINCRBY, ZSCORE.
* An utility able to export an .rdb file into a text-only JSON dump, we can't live anymore without such a tool. Probably an extension to redis-cli.

After 1.1 todo
Expand Down
2 changes: 1 addition & 1 deletion client-libraries/tcl/redis.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ array set ::redis::multibulkarg {}

# Flag commands requiring last argument as a bulk write operation
foreach redis_bulk_cmd {
set setnx rpush lpush lset lrem sadd srem sismember echo getset smove zadd
set setnx rpush lpush lset lrem sadd srem sismember echo getset smove zadd zrem
} {
set ::redis::bulkarg($redis_bulk_cmd) {}
}
Expand Down
1 change: 1 addition & 0 deletions redis-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static struct redisCommand cmdTable[] = {
{"sdiffstore",-3,REDIS_CMD_INLINE},
{"smembers",2,REDIS_CMD_INLINE},
{"zadd",4,REDIS_CMD_BULK},
{"zrem",3,REDIS_CMD_BULK},
{"zrange",4,REDIS_CMD_INLINE},
{"zlen",2,REDIS_CMD_INLINE},
{"incrby",3,REDIS_CMD_INLINE},
Expand Down
38 changes: 38 additions & 0 deletions redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ static void msetnxCommand(redisClient *c);
static void zaddCommand(redisClient *c);
static void zrangeCommand(redisClient *c);
static void zlenCommand(redisClient *c);
static void zremCommand(redisClient *c);

/*================================= Globals ================================= */

Expand Down Expand Up @@ -475,6 +476,7 @@ static struct redisCommand cmdTable[] = {
{"sdiffstore",sdiffstoreCommand,-3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM},
{"smembers",sinterCommand,2,REDIS_CMD_INLINE},
{"zadd",zaddCommand,4,REDIS_CMD_BULK|REDIS_CMD_DENYOOM},
{"zrem",zremCommand,3,REDIS_CMD_BULK},
{"zrange",zrangeCommand,4,REDIS_CMD_INLINE},
{"zlen",zlenCommand,2,REDIS_CMD_INLINE},
{"incrby",incrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM},
Expand Down Expand Up @@ -3853,6 +3855,41 @@ static void zaddCommand(redisClient *c) {
}
}

static void zremCommand(redisClient *c) {
robj *zsetobj;
zset *zs;

zsetobj = lookupKeyWrite(c->db,c->argv[1]);
if (zsetobj == NULL) {
addReply(c,shared.czero);
} else {
dictEntry *de;
double *oldscore;
int deleted;

if (zsetobj->type != REDIS_ZSET) {
addReply(c,shared.wrongtypeerr);
return;
}
zs = zsetobj->ptr;
de = dictFind(zs->dict,c->argv[2]);
if (de == NULL) {
addReply(c,shared.czero);
return;
}
/* Delete from the skiplist */
oldscore = dictGetEntryVal(de);
deleted = zslDelete(zs->zsl,*oldscore,c->argv[2]);
assert(deleted != 0);

/* Delete from the hash table */
dictDelete(zs->dict,c->argv[2]);
if (htNeedsResize(zs->dict)) dictResize(zs->dict);
server.dirty++;
addReply(c,shared.cone);
}
}

static void zrangeCommand(redisClient *c) {
robj *o;
int start = atoi(c->argv[2]->ptr);
Expand Down Expand Up @@ -4980,6 +5017,7 @@ static struct redisFunctionSym symsTable[] = {
{"createZsetObject",(unsigned long)createZsetObject},
{"zaddCommand",(unsigned long)zaddCommand},
{"zrangeCommand",(unsigned long)zrangeCommand},
{"zremCommand",(unsigned long)zremCommand},
{NULL,0}
};

Expand Down

0 comments on commit 1b7106e

Please sign in to comment.