You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
A Redis List is a linked list of string values associated with a single key. Lists maintain insertion order and support efficient push and pop operations from both ends, making them ideal for queues, stacks, activity feeds, and log buffers.
LPUSH adds one or more elements to the left (head) of the list. RPUSH adds to the right (tail):
127.0.0.1:6379> RPUSH tasks "send email" "generate report" "clean cache"
(integer) 3
127.0.0.1:6379> LPUSH tasks "urgent fix"
(integer) 4
Multiple values can be pushed in one command. With RPUSH, the first argument ends up leftmost; with LPUSH, the last argument ends up leftmost.
Retrieve a range of elements by index (zero-based, negative indices count from the tail):
127.0.0.1:6379> LRANGE tasks 0 -1
1) "urgent fix"
2) "send email"
3) "generate report"
4) "clean cache"
LRANGE tasks 0 -1 returns the entire list. LRANGE tasks 0 2 returns the first three elements.
Remove and return an element from either end:
# Dequeue from the left (FIFO queue pattern)
127.0.0.1:6379> LPOP tasks
"urgent fix"
# Pop from the right (stack pattern)
127.0.0.1:6379> RPOP tasks
"clean cache"
Since Redis 6.2 you can pop multiple elements at once:
127.0.0.1:6379> LPOP tasks 2
1) "send email"
2) "generate report"
127.0.0.1:6379> LLEN tasks
(integer) 0
127.0.0.1:6379> RPUSH log "event1" "event2" "event3"
(integer) 3
127.0.0.1:6379> LINDEX log 1
"event2"
BLPOP and BRPOP block the client until an element is available or a timeout is reached. This makes them perfect for implementing worker queues:
# Worker blocks for up to 30 seconds waiting for a job
127.0.0.1:6379> BLPOP job_queue 30
When another client pushes to job_queue, the blocked worker is unblocked and receives the element immediately — no polling required.
Keep only the most recent N entries in a log or feed:
127.0.0.1:6379> RPUSH activity_feed "login" "view_product" "add_to_cart" "checkout"
(integer) 4
# Keep only the last 3 entries
127.0.0.1:6379> LTRIM activity_feed -3 -1
OK
127.0.0.1:6379> LRANGE activity_feed 0 -1
1) "view_product"
2) "add_to_cart"
3) "checkout"
Lists are the backbone of Redis-based task queues and streaming log patterns.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.