XREVRANGE
Syntax
XREVRANGE key end start [COUNT count]
- Available since:
- 5.0.0
- Time complexity:
- O(N) with N being the number of elements returned. If N is constant (e.g. always asking for the first 10 elements with COUNT), you can consider it O(1).
- ACL categories:
-
@read
,@stream
,@slow
,
此命令与XRANGE
完全相同,但有一个显著的区别是它以相反的顺序返回条目,并且也以相反的顺序接受开始-结束范围:在XREVRANGE
中,您需要先指定结束ID,然后是开始ID,命令将从结束侧生成两个ID之间(或完全相同)的所有元素。
例如,要获取从较高ID到较低ID的所有元素,可以使用:
XREVRANGE somestream + -
同样地,要获取刚刚添加到流中的最后一个元素,只需发送:
XREVRANGE somestream + - COUNT 1
示例
RESP2/RESP3 回复
Array reply: The command returns the entries with IDs matching the specified range. The returned entries are complete, which means that the ID and all the fields they are composed of are returned. Moreover, the entries are returned with their fields and values in the same order asXADD
added them.
历史
- 从 Redis 版本 6.2.0 开始:添加了独占范围。