Redis – Sorted Set Zrank Command

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

Redis ZRANK command returns the rank of member in the sorted set stored at the 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.

Return Value

  • If the member exists in the sorted set, Integer reply: the rank of member.
  • If the member does not exist in the sorted set or the key does not exist, Bulk string reply − nil.

Syntax

Following is the basic syntax of Redis ZRANK command.

redis 127.0.0.1:6379> ZRANK key member

Example

redis 127.0.0.1:6379> ZADD myzset 0 a 1 b 2 c 3 d 4 e 
(integer) 5 
redis 127.0.0.1:6379> ZADD myzset 5 f 6 g 
(integer) 2 
redis 127.0.0.1:6379> ZRANK myzset b 
(integer) 1 
redis 127.0.0.1:6379> ZRANK myzset t 
nil 

Leave a Reply