mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
Merged ZREVRANK from Pietern
This commit is contained in:
commit
e3f46030fc
16
redis.c
16
redis.c
@ -674,6 +674,7 @@ static void brpopCommand(redisClient *c);
|
|||||||
static void appendCommand(redisClient *c);
|
static void appendCommand(redisClient *c);
|
||||||
static void substrCommand(redisClient *c);
|
static void substrCommand(redisClient *c);
|
||||||
static void zrankCommand(redisClient *c);
|
static void zrankCommand(redisClient *c);
|
||||||
|
static void zrevrankCommand(redisClient *c);
|
||||||
static void hsetCommand(redisClient *c);
|
static void hsetCommand(redisClient *c);
|
||||||
static void hgetCommand(redisClient *c);
|
static void hgetCommand(redisClient *c);
|
||||||
|
|
||||||
@ -730,6 +731,7 @@ static struct redisCommand cmdTable[] = {
|
|||||||
{"zcard",zcardCommand,2,REDIS_CMD_INLINE,1,1,1},
|
{"zcard",zcardCommand,2,REDIS_CMD_INLINE,1,1,1},
|
||||||
{"zscore",zscoreCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM,1,1,1},
|
{"zscore",zscoreCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM,1,1,1},
|
||||||
{"zrank",zrankCommand,3,REDIS_CMD_INLINE,1,1,1},
|
{"zrank",zrankCommand,3,REDIS_CMD_INLINE,1,1,1},
|
||||||
|
{"zrevrank",zrevrankCommand,3,REDIS_CMD_INLINE,1,1,1},
|
||||||
{"hset",hsetCommand,4,REDIS_CMD_BULK|REDIS_CMD_DENYOOM,1,1,1},
|
{"hset",hsetCommand,4,REDIS_CMD_BULK|REDIS_CMD_DENYOOM,1,1,1},
|
||||||
{"hget",hgetCommand,3,REDIS_CMD_BULK,1,1,1},
|
{"hget",hgetCommand,3,REDIS_CMD_BULK,1,1,1},
|
||||||
{"incrby",incrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM,1,1,1},
|
{"incrby",incrbyCommand,3,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM,1,1,1},
|
||||||
@ -5637,7 +5639,7 @@ static void zscoreCommand(redisClient *c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zrankCommand(redisClient *c) {
|
static void zrankGenericCommand(redisClient *c, int reverse) {
|
||||||
robj *o;
|
robj *o;
|
||||||
o = lookupKeyRead(c->db,c->argv[1]);
|
o = lookupKeyRead(c->db,c->argv[1]);
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
@ -5661,13 +5663,25 @@ static void zrankCommand(redisClient *c) {
|
|||||||
double *score = dictGetEntryVal(de);
|
double *score = dictGetEntryVal(de);
|
||||||
rank = zslGetRank(zsl, *score, c->argv[2]);
|
rank = zslGetRank(zsl, *score, c->argv[2]);
|
||||||
if (rank) {
|
if (rank) {
|
||||||
|
if (reverse) {
|
||||||
|
addReplyLong(c, zsl->length - rank);
|
||||||
|
} else {
|
||||||
addReplyLong(c, rank-1);
|
addReplyLong(c, rank-1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
addReply(c,shared.nullbulk);
|
addReply(c,shared.nullbulk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void zrankCommand(redisClient *c) {
|
||||||
|
zrankGenericCommand(c, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void zrevrankCommand(redisClient *c) {
|
||||||
|
zrankGenericCommand(c, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/* =================================== Hashes =============================== */
|
/* =================================== Hashes =============================== */
|
||||||
static void hsetCommand(redisClient *c) {
|
static void hsetCommand(redisClient *c) {
|
||||||
int update = 0;
|
int update = 0;
|
||||||
|
@ -1204,6 +1204,10 @@ proc main {server port} {
|
|||||||
list [$r zrank zranktmp x] [$r zrank zranktmp y] [$r zrank zranktmp z]
|
list [$r zrank zranktmp x] [$r zrank zranktmp y] [$r zrank zranktmp z]
|
||||||
} {0 1 2}
|
} {0 1 2}
|
||||||
|
|
||||||
|
test {ZREVRANK basics} {
|
||||||
|
list [$r zrevrank zranktmp x] [$r zrevrank zranktmp y] [$r zrevrank zranktmp z]
|
||||||
|
} {2 1 0}
|
||||||
|
|
||||||
test {ZRANK - after deletion} {
|
test {ZRANK - after deletion} {
|
||||||
$r zrem zranktmp y
|
$r zrem zranktmp y
|
||||||
list [$r zrank zranktmp x] [$r zrank zranktmp z]
|
list [$r zrank zranktmp x] [$r zrank zranktmp z]
|
||||||
|
Loading…
Reference in New Issue
Block a user