Easy Tutorial
❮ Lists Lpop Keys Pexpireat ❯

Redis Zrank Command

Redis Sorted Set

Redis Zrank returns the rank of a specified member in the sorted set. The members of the sorted set are ordered by their score values in ascending (from smallest to largest) order.

Syntax

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

redis 127.0.0.1:6379> ZRANK key member

Available Versions

= 2.0.0

Return Value

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

Example

redis 127.0.0.1:6379> ZRANGE salary 0 -1 WITHSCORES        # Displays all members and their score values
1) "peter"
2) "3500"
3) "tom"
4) "4000"
5) "jack"
6) "5000"

redis 127.0.0.1:6379> ZRANK salary tom                     # Displays the salary rank of tom, which is second
(integer) 1

Redis Sorted Set

❮ Lists Lpop Keys Pexpireat ❯