XREVRANGE
XREVRANGE key end start [COUNT count]
- Group
- Stream
- Complexity
- O(log N + M), M being the entries returned
- Arity
- -4 (at least 4 words, counting the command name)
- Flags
- read-only
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
XREVRANGE works like XRANGE but returns entries in
descending ID order, and takes the bounds in the opposite order: the higher
bound (end) first, then the lower bound (start).
The bounds accept the same forms as XRANGE: +, -, a full ID, a bare
millisecond time (as end it means the last ID of that millisecond, as
start the first), and ( before an ID to exclude it.
Options
Section titled “Options”| Option | Effect |
|---|---|
COUNT count |
Return at most count entries, starting from the newest. |
Return value
Section titled “Return value”An array of entries, each [id, [field, value, ...]], in the same shape for
RESP2 and RESP3.
| Case | RESP2 | RESP3 |
|---|---|---|
| Entries in range | Array of entries, newest first | Array of entries |
| Nothing in range, or no such key | Empty array | Empty array |
COUNT of 0 or less on an existing stream |
Nil array | Null |
The error replies are the same as for XRANGE, including WRONGTYPE.
Examples
Section titled “Examples”127.0.0.1:6379> XADD log 1700000000000-0 msg a"1700000000000-0"127.0.0.1:6379> XADD log 1700000000001-0 msg b"1700000000001-0"127.0.0.1:6379> XADD log 1700000000002-0 msg c"1700000000002-0"127.0.0.1:6379> XREVRANGE log + - COUNT 21) 1) "1700000000002-0" 2) 1) "msg" 2) "c"2) 1) "1700000000001-0" 2) 1) "msg" 2) "b"Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.