mirror of
http://github.com/valkey-io/valkey
synced 2024-11-23 03:33:28 +00:00
ZSCORE implemented
This commit is contained in:
parent
dbbc7285ee
commit
6e333bbee2
2
TODO
2
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[] = {
|
|||||||
{"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},
|
||||||
|
32
redis.c
32
redis.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[] = {
|
|||||||
{"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) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user