Commit 6e333bbe authored by antirez's avatar antirez
Browse files

ZSCORE implemented

parent dbbc7285
...@@ -3,7 +3,7 @@ Pre 1.1 todo ...@@ -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". * 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. * Man pages for MSET MSETNX and SRANDMEMBER.
* Hashes (HSET, HGET, HEXISTS, HLEN, ...). * Hashes (HSET, HGET, HEXISTS, HLEN, ...).
* ZSETs missing stuff: ZINCRBY, ZSCORE, ZREVRANGE, ZRANGEBYSCORE * ZSETs missing stuff: 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. * 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 After 1.1 todo
......
...@@ -95,6 +95,7 @@ static struct redisCommand cmdTable[] = { ...@@ -95,6 +95,7 @@ static struct redisCommand cmdTable[] = {
{"zrangebyscore",4,REDIS_CMD_INLINE}, {"zrangebyscore",4,REDIS_CMD_INLINE},
{"zrevrange",4,REDIS_CMD_INLINE}, {"zrevrange",4,REDIS_CMD_INLINE},
{"zlen",2,REDIS_CMD_INLINE}, {"zlen",2,REDIS_CMD_INLINE},
{"zscore",3,REDIS_CMD_BULK},
{"incrby",3,REDIS_CMD_INLINE}, {"incrby",3,REDIS_CMD_INLINE},
{"decrby",3,REDIS_CMD_INLINE}, {"decrby",3,REDIS_CMD_INLINE},
{"getset",3,REDIS_CMD_BULK}, {"getset",3,REDIS_CMD_BULK},
......
...@@ -448,6 +448,7 @@ static void zrangebyscoreCommand(redisClient *c); ...@@ -448,6 +448,7 @@ static void zrangebyscoreCommand(redisClient *c);
static void zrevrangeCommand(redisClient *c); static void zrevrangeCommand(redisClient *c);
static void zlenCommand(redisClient *c); static void zlenCommand(redisClient *c);
static void zremCommand(redisClient *c); static void zremCommand(redisClient *c);
static void zscoreCommand(redisClient *c);
/*================================= Globals ================================= */ /*================================= Globals ================================= */
...@@ -492,6 +493,7 @@ static struct redisCommand cmdTable[] = { ...@@ -492,6 +493,7 @@ static struct redisCommand cmdTable[] = {
{"zrangebyscore",zrangebyscoreCommand,4,REDIS_CMD_INLINE}, {"zrangebyscore",zrangebyscoreCommand,4,REDIS_CMD_INLINE},
{"zrevrange",zrevrangeCommand,4,REDIS_CMD_INLINE}, {"zrevrange",zrevrangeCommand,4,REDIS_CMD_INLINE},
{"zlen",zlenCommand,2,REDIS_CMD_INLINE}, {"zlen",zlenCommand,2,REDIS_CMD_INLINE},
{"zscore",zscoreCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM},
{"incrby",incrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM}, {"incrby",incrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM},
{"decrby",decrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM}, {"decrby",decrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM},
{"getset",getsetCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM}, {"getset",getsetCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM},
...@@ -4159,6 +4161,36 @@ static void zlenCommand(redisClient *c) { ...@@ -4159,6 +4161,36 @@ static void zlenCommand(redisClient *c) {
} }
} }
static void zscoreCommand(redisClient *c) {
robj *o;
zset *zs;
o = lookupKeyRead(c->db,c->argv[1]);
if (o == NULL) {
addReply(c,shared.czero);
return;
} else {
if (o->type != REDIS_ZSET) {
addReply(c,shared.wrongtypeerr);
} else {
dictEntry *de;
zs = o->ptr;
de = dictFind(zs->dict,c->argv[2]);
if (!de) {
addReply(c,shared.nullbulk);
} else {
char buf[128];
double *score = dictGetEntryVal(de);
snprintf(buf,sizeof(buf),"%.16g",*score);
addReplySds(c,sdscatprintf(sdsempty(),"$%d\r\n%s\r\n",
strlen(buf),buf));
}
}
}
}
/* ========================= Non type-specific commands ==================== */ /* ========================= Non type-specific commands ==================== */
static void flushdbCommand(redisClient *c) { static void flushdbCommand(redisClient *c) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment