w3resource

Redis Sorted Sets: ZRANK

ZRANK key member

Redis ZRANK command is used to return the rank of member in the sorted set stored at key, with the scores ordered from low to high. The rank is 0-based, which means that the member with the lowest score has rank 0.

Syntax:

ZRANK key member

Available since

2.0.0.

Return Value

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

Return Value Type

Integer

Example: Redis ZRANK

127.0.0.1:6379> ZADD mysales 1556 Samsung 2000 Nokia 1800 Micromax
(integer) 3
127.0.0.1:6379> ZADD mysales 2200 Sunsui 1800 MicroSoft 2500 LG
(integer) 3
127.0.0.1:6379> ZRANGE mysales 0 -1 WITHSCORES
 1) "Samsung"
 2) "1556"
 3) "MicroSoft"
 4) "1800"
 5) "Micromax"
 6) "1800"
 7) "Nokia"
 8) "2000"
 9) "Sunsui"
10) "2200"
11) "LG"
12) "2500"
127.0.0.1:6379> ZRANGE mysales 0 -1 WITHSCORES
 1) "Samsung"
 2) "1556"
 3) "MicroSoft"
 4) "1800"
 5) "Micromax"
 6) "1800"
 7) "Nokia"
 8) "2000"
 9) "Sunsui"
10) "2200"
11) "LG"
12) "2500"
127.0.0.1:6379> ZRANK mysales "Sunsui"
(integer) 4
127.0.0.1:6379> ZRANK mysales MicroSoft
(integer) 1

Previous: ZRANGEBYSCORE
Next: ZREM



Follow us on Facebook and Twitter for latest update.