原文
http://redis.io/commands/zrank
简介
Determine the index of a member in a sorted set.
确定有序集合中成员的索引。
语法
ZRANK key member
版本
Available since 2.0.0.
自2.0.0版本可用。
时间复杂度
Time complexity: O(log(N))
描述
Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. The rank (or index) is 0-based, which means that the member with the lowest score has rank 0.
返回有序集合中成员的次序,按照分数从低到高排序。次序(或索引)是基于0的,这意味着分数最低的成员的次序为0。
Use ZREVRANK to get the rank of an element with the scores ordered from high to low.
使用ZREVRANGE获取元素的次序,按照分数由高到低排序。
返回值
If member exists in the sorted set, Integer reply: the rank of member.
If member does not exist in the sorted set or key does not exist, Bulk string reply: nil.
1)如果成员在有序集合中存在,返回成员的次序。
2)如果成员在有序集合中不存在,或者key不存在,返回nil。
例子
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZRANK myzset "three"
(integer) 2
redis> ZRANK myzset "four"
(nil)
redis>