Redis Lists: LRANGE
Redis LRANGE Command
Redis LRANGE command is used to return the specified elements of the list stored at key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list, 1 being the next element and so on.
Here are some common uses and scenarios for the "LRANGE" command:
- Pagination: Fetch a subset of elements to implement pagination.
- Data Inspection: Retrieve specific segments of data for analysis or reporting.
- Task Management: Manage tasks by fetching a range of elements from a task queue.
- Event Handling: Process events or messages within a specified range in an event list.
- Data Processing Pipelines: Retrieve a batch of data from a pipeline for subsequent processing.
Syntax:
LRANGE KEY_NAME START END
Available since
1.0.0.
Return Value
Array reply, a list of elements in the specified range.
Return Value Type
Array
Example: Redis LRANGE
127.0.0.1:6379> LPUSH mycolor1 white black red blue (integer) 4 127.0.0.1:6379> LRANGE mycolor1 0 -1 1) "blue" 2) "red" 3) "black" 4) "white" 127.0.0.1:6379> LRANGE mycolor1 0 1 1) "blue" 2) "red" 127.0.0.1:6379> LRANGE mycolor1 2 -1 1) "black" 2) "white"
Example: Redis LRANGE: using negative right data
127.0.0.1:6379> LRANGE mycolor1 -2 -1 1) "black" 2) "white" 127.0.0.1:6379> LRANGE mycolor1 -4 -3 1) "blue" 2) "red" 127.0.0.1:6379> LRANGE mycolor1 0 -3 1) "blue" 2) "red"
Example: Redis LRANGE: Range error does not occur
127.0.0.1:6379> LRANGE mycolor1 3 20 1) "white" 127.0.0.1:6379> LRANGE mycolor1 -20 -10 (empty list or set)
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/redis/redis-lrange-key-start-stop.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics