Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Command

LRANGE

Returns an inclusive range of elements from a Redis list. Start and stop use zero-based indexes, and negative indexes count from the list's tail.

Since
1.0.0

How it works

LRANGE reads the elements between the supplied zero-based start and stop positions from a Redis list. Both boundaries are inclusive, negative positions count backward from the tail, and indexes outside the list are tolerated rather than treated as errors.

Syntax

LRANGE key start stop

Parameters

NameTypeDescription
keykeyName of the key that holds the list.
startintegerZero-based starting index; negative indexes count from the tail.
stopintegerInclusive zero-based ending index; negative indexes count from the tail.

Returns

An array containing the selected list elements, or an empty array if the key does not exist.

Key points

  • LRANGE selects and returns elements from the list associated with the specified key.
  • Both positions use zero-based indexing, with the first list element at position zero.
  • The stop boundary is included in the returned range.
  • A negative position measures backward from the list's final element.
  • Runtime is O(S+N), combining the traversal distance to the start with the number of returned items.

Common mistakes

  • Indexes beyond the list boundaries are accepted; they simply select whatever portion overlaps the list.
  • A start position after the list's end produces no elements.
  • A missing key returns an empty array rather than an error.

Example: Read a complete Redis list

redis-cli RPUSH mylist one two three
redis-cli LRANGE mylist 0 -1
# 1) "one"
# 2) "two"
# 3) "three"

Adds three values, then reads the entire list with an inclusive range from the first element through the last.

When to use it

List retrieval and pagination

Read all values in a list with 0 -1 or fetch a bounded slice for display.

Recent-item inspection

Inspect the newest entries by using a negative range such as -5 -1.

Queue monitoring

Read a queue segment without removing its jobs.

Interview questions

QHow do LRANGE indexes work?

LRANGE returns a selected portion of a list using zero-based start and stop indexes. The stop index is inclusive, so 0 0 reads the first element and 0 -1 reads the whole list.

Follow-up: How does it behave when indexes exceed the list? Out-of-range indexes do not cause errors; the result contains the overlapping elements, or is empty when the range does not overlap.

QWhat do negative indexes mean in LRANGE?

Negative indexes count from the tail: -1 identifies the last element, -2 the previous one, and so forth. This makes 0 -1 a convenient full-list read.

Follow-up: What happens if the key is absent? Redis returns an empty array.

QWhat is LRANGE's time complexity?

The command has O(S+N) complexity, where S is the distance from the relevant list end to the start offset and N is the number of returned elements. Reading a large range therefore costs more than reading a small one.

Follow-up: Which list operation can prepare the example list? RPUSH appends values to the list, after which LRANGE can read them.

  • RPUSH
  • LPOP
  • LLEN

Source: LRANGE | Docs - Redis. Checked 2026-10-16.