Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Zrank command

Redis Zrank command

Redis Sorted Set

Redis Zrank returns the rank of a specified member in a sorted set. Members are ordered by ascending score value (from low to high).

Syntax

The basic syntax of the redis Zrank command is as follows:

redis 127.0.0.1:6379> ZRANK key member

Available Version

>= 2.0.0

Return Value

If the member is a member of the sorted set key, returns the rank of member. If the member is not a member of the sorted set key, returns nil.

Example

redis 127.0.0.1:6379> ZRANGE salary 0 -1 WITHSCORES        # 显示所有成员及其 score 值

1) "peter"

2) "3500"

3) "tom"

4) "4000"

5) "jack"

6) "5000"

redis 127.0.0.1:6379> ZRANK salary tom # 显示 tom 的薪水排名,第二 (integer) 1

Redis Sorted Set