# ZREVRANK

> Get the rank of a member in a sorted set, highest score first.

URL: https://docs.hotkv.com/commands/zrevrank/

```
ZREVRANK key member [WITHSCORE]
```

- Group: Sorted set
- Complexity: O(log(N)) where N is the size of the sorted set
- HotKV Cloud: all plans
- On-Premise: no license needed

`ZREVRANK` returns the position of `member` in the sorted set at `key`, ordered
from the highest score to the lowest. The highest-scored member has rank `0`.
It is the mirror of [ZRANK](https://docs.hotkv.com/commands/zrank/index.md).

## Options

| Option | Effect |
| --- | --- |
| `WITHSCORE` | Also return the member's score. |

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Member exists | Integer: the rank | Same |
| Member exists, with `WITHSCORE` | Two-element array: the rank (integer) and the score (bulk string) | Two-element array: the rank (integer) and the score (double) |
| Member or key does not exist | Nil bulk string | Null |
| Member or key does not exist, with `WITHSCORE` | Nil array | Null |

Errors:

- `ERR syntax error` if the third argument is not `WITHSCORE`.
- `WRONGTYPE` if `key` holds a value that is not a sorted set.

## Examples

```
127.0.0.1:6379> ZADD board 100 "alice" 90 "bob" 95 "carol"
(integer) 3
127.0.0.1:6379> ZREVRANK board "alice"
(integer) 0
127.0.0.1:6379> ZREVRANK board "bob" WITHSCORE
1) (integer) 2
2) "90"
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[ZRANK](https://docs.hotkv.com/commands/zrank/index.md), [ZSCORE](https://docs.hotkv.com/commands/zscore/index.md), [ZREVRANGE](https://docs.hotkv.com/commands/zrevrange/index.md)