Skip to main content
A list is an ordered sequence of string elements associated with a single key. Elements are kept in insertion order and you can efficiently push or pop from either end in O(1) time. This makes lists ideal for queues, stacks, activity feeds, and any other scenario where the order of elements matters and you regularly add or remove items from the edges.

LPUSH

Prepends one or more values to the head (left side) of the list stored at key. If key does not exist, an empty list is created first. When you supply multiple values, they are pushed left-to-right, so the last value you specify ends up at the head. Syntax: LPUSH key value [value ...]
LPUSH tasks "task3"
# (integer) 1

LPUSH tasks "task2" "task1"
# (integer) 3

LRANGE tasks 0 -1
# 1) "task1"
# 2) "task2"
# 3) "task3"
Returns: Integer — the new length of the list after the push.

RPUSH

Appends one or more values to the tail (right side) of the list stored at key. If key does not exist, an empty list is created first. Multiple values are appended left-to-right, so the last value you specify ends up at the tail. Syntax: RPUSH key value [value ...]
RPUSH tasks "task1" "task2" "task3"
# (integer) 3

LRANGE tasks 0 -1
# 1) "task1"
# 2) "task2"
# 3) "task3"
Returns: Integer — the new length of the list after the push.

LPOP

Removes and returns the element at the head (left side) of the list stored at key. Syntax: LPOP key
RPUSH queue "job1" "job2" "job3"

LPOP queue
# "job1"

LRANGE queue 0 -1
# 1) "job2"
# 2) "job3"
Returns: Bulk string — the removed element, or nil if the list is empty or the key does not exist.

RPOP

Removes and returns the element at the tail (right side) of the list stored at key. Syntax: RPOP key
RPUSH stack "a" "b" "c"

RPOP stack
# "c"
Returns: Bulk string — the removed element, or nil if the list is empty or the key does not exist.

LLEN

Returns the number of elements in the list stored at key. Syntax: LLEN key
RPUSH mylist "a" "b" "c"
LLEN mylist
# (integer) 3

LLEN nonexistent
# (integer) 0
Returns: Integer — the list length, or 0 if the key does not exist.

LINDEX

Returns the element at position index in the list stored at key. Indices are zero-based from the head. Negative indices count back from the tail: -1 is the last element, -2 is the second-to-last, and so on. Syntax: LINDEX key index
RPUSH colors "red" "green" "blue"

LINDEX colors 0
# "red"

LINDEX colors -1
# "blue"

LINDEX colors 10
# (nil)
Returns: Bulk string — the element at the given index, or nil if the index is out of range or the key does not exist.

LRANGE

Returns the specified sub-range of the list stored at key. Both start and stop are inclusive, and both support negative indices. Requesting a range that extends past the end of the list is not an error — Cache-Pot clamps the range to the actual list bounds. Syntax: LRANGE key start stop
RPUSH letters "a" "b" "c" "d" "e"

LRANGE letters 0 2
# 1) "a"
# 2) "b"
# 3) "c"

LRANGE letters -3 -1
# 1) "c"
# 2) "d"
# 3) "e"

LRANGE letters 0 -1
# 1) "a"
# 2) "b"
# 3) "c"
# 4) "d"
# 5) "e"
Returns: Array of bulk strings for the requested range. Returns an empty array if the key does not exist or the range is empty.

Practical example: task queue

Lists map naturally onto a FIFO queue. Use RPUSH to enqueue work and LPOP to dequeue it:
# Enqueue three tasks
RPUSH tasks "task1" "task2" "task3"
# (integer) 3

# How many tasks are pending?
LLEN tasks
# (integer) 3

# Dequeue the oldest task (FIFO)
LPOP tasks
# "task1"

# Peek at the remaining queue
LRANGE tasks 0 -1
# 1) "task2"
# 2) "task3"
Flip LPUSH + RPOP to get a LIFO stack, or use LPUSH + LPOP / RPUSH + RPOP for stack semantics from either end.
LPOP and RPOP return nil on an empty list rather than blocking. If you need a worker that waits for new items, consider polling with a short sleep or pairing lists with a pub/sub notification.