mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
fix ZRANK (realize that rank is 1-based due to the skip list header)
This commit is contained in:
parent
3919155375
commit
67cac14343
9
redis.c
9
redis.c
@ -5483,13 +5483,16 @@ static void zrankCommand(redisClient *c) {
|
|||||||
while (x->forward[i] &&
|
while (x->forward[i] &&
|
||||||
(x->forward[i]->score < *score ||
|
(x->forward[i]->score < *score ||
|
||||||
(x->forward[i]->score == *score &&
|
(x->forward[i]->score == *score &&
|
||||||
compareStringObjects(x->forward[i]->obj,c->argv[2]) < 0))) {
|
compareStringObjects(x->forward[i]->obj,c->argv[2]) <= 0))) {
|
||||||
rank += x->span[i];
|
rank += x->span[i];
|
||||||
x = x->forward[i];
|
x = x->forward[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x->forward[i] && compareStringObjects(x->forward[i]->obj,c->argv[2]) == 0) {
|
/* x might be equal to zsl->header, so test if obj is non-NULL */
|
||||||
addReplyLong(c, rank);
|
if (x->obj && compareStringObjects(x->obj,c->argv[2]) == 0) {
|
||||||
|
/* the pointer from zsl->header to the first element also spans one,
|
||||||
|
* which makes the rank 1-based */
|
||||||
|
addReplyLong(c, rank-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1545,7 +1545,7 @@ proc main {server port} {
|
|||||||
set ele [lindex [$r zrange myzset $index $index] 0]
|
set ele [lindex [$r zrange myzset $index $index] 0]
|
||||||
set rank [$r zrank myzset $ele]
|
set rank [$r zrank myzset $ele]
|
||||||
if {$rank != $index} {
|
if {$rank != $index} {
|
||||||
set err "$ele RANK is wrong! ($rank != [expr $index+1])"
|
set err "$ele RANK is wrong! ($rank != $index)"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user