Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
67cac143
Commit
67cac143
authored
Mar 04, 2010
by
Pieter Noordhuis
Browse files
fix ZRANK (realize that rank is 1-based due to the skip list header)
parent
39191553
Changes
2
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
67cac143
...
@@ -5483,13 +5483,16 @@ static void zrankCommand(redisClient *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
;
}
}
}
}
...
...
test-redis.tcl
View file @
67cac143
...
@@ -1545,7 +1545,7 @@ proc main {server port} {
...
@@ -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
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment