Skip to content

ZRANK

ZRANK key member

ZRANK returns the rank of a member in a sorted set, ordered from low to high scores.

The rank is 1-based which means that the member with the lowest score has rank 1, the next highest has rank 2, and so on. The command returns the element - rank, score, and memeber.

Thus, 1), 2), 3) are the rank of the element in the sorted set, followed by the score and the member.

The the member passed as the second argument is not a member of the sorted set, the command returns a valid response with a rank of 0 and score of 0. If the key does not exist, the command returns a valid response with a rank of 0, score of 0, and the member as "".

localhost:7379> ZADD users 10 alice 20 bob 30 charlie
OK 3
localhost:7379> ZRANK users bob
OK 2) 20, bob
localhost:7379> ZRANK users charlie
OK 3) 30, charlie
localhost:7379> ZRANK users daniel
OK 0) 0, daniel