XREVRANGE

XREVRANGE key end start [COUNT count]

This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, and also taking the start-end range in reverse order: in XREVRANGE you need to state the end ID and later the start ID, and the command will produce all the element between (or exactly like) the two IDs, starting from the end side.

So for instance, to get all the elements from the higher ID to the lower ID one could use:

XREVRANGE somestream + -

Similarly to get just the last element added into the stream it is enough to send:

XREVRANGE somestream + - COUNT 1

Return value

Array reply, specifically:

The command returns the entries with IDs matching the specified range, from the higher ID to the lower ID matching. The returned entries are complete, that means that the ID and all the fields they are composed are returned. Moreover the entries are returned with their fields and values in the exact same order as XADD added them.

History

  • >= 6.2 Added exclusive ranges.

Examples

redis> XADD writers * name Virginia surname Woolf "1614929920279-0" redis> XADD writers * name Jane surname Austen "1614929920280-0" redis> XADD writers * name Toni surname Morrison "1614929920280-1" redis> XADD writers * name Agatha surname Christie "1614929920280-2" redis> XADD writers * name Ngozi surname Adichie "1614929920280-3" redis> XLEN writers (integer) 5 redis> XREVRANGE writers + - COUNT 1 1) 1) "1614929920280-3" 2) 1) "name" 2) "Ngozi" 3) "surname" 4) "Adichie"

© 2009–2020 Salvatore Sanfilippo
Licensed under the Creative Commons Attribution-ShareAlike License 4.0.
https://redis.io/commands/xrevrange