LREVRANGE

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Get a list range in reverse (right to left) by index

Usage is lrevrange key start stop.
From right to left, the first value is -1, the second is -2, and the third is -3.
To get the whole list, set start to -1 and stop to 0.

This command is available in the Enterprise version.

Example

Command>lpush mylist value1 value2 value3 value4
Result>4
Command>lrevrange mylist -1 0
Result> 0) value1
1) value2
2) value3
3) value4
Command>lrevrange mylist 1 0
Result> 0) value3
1) value4
Command>lrevrange mylist -1 2
Result> 0) value1
1) value2

View animation


Sort feature

SORT or ASC sorts in ascending order, DESC sorts in descending order.

Example

Command>lrevrange mylist -1 0 sort
Result>1) value1
2) value2
3) value3
4) value4
Command>lrevrange mylist -1 0 desc
Result>1) value4
2) value3
3) value2
4) value1

Syntax

LREVRANGE key start stop [sort|asc|desc]

  • Available since Redis Enterprise version 6.0.0.
  • Time complexity is O(S+N). S is start and N is the number of elements.
Related commands LPUSH, RPUSH, LPOP, RPOP
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< LLS LREVRANGE LLEN >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.