Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

XREVRANGE

Last updated
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.

Option Effect
COUNT count Return at most count entries, starting from the newest.

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.

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 2
1) 1) "1700000000002-0"
2) 1) "msg"
2) "c"
2) 1) "1700000000001-0"
2) 1) "msg"
2) "b"

Same as Redis 7 and Valkey 8.

XRANGE, XREAD, XADD