Script Valley
Redis: Complete Course
Core Commands and Data StructuresLesson 2.3

Redis List commands: LPUSH, RPUSH, LPOP, LRANGE, LLEN

LPUSH RPUSH, LPOP RPOP, LRANGE, LLEN, LINDEX, LSET, LTRIM, blocking BLPOP, queue vs stack pattern

Lists as queues and stacks

A Redis List is a doubly-linked list of strings. Push and pop from either end in O(1). Use it as a queue (RPUSH + LPOP) or a stack (RPUSH + RPOP).

Basic operations

RPUSH jobs "send-email" "resize-image" "send-sms"
LLEN jobs        # โ†’ 3
LRANGE jobs 0 -1 # โ†’ ["send-email", "resize-image", "send-sms"]
LPOP jobs        # โ†’ "send-email" (dequeue from front)
LINDEX jobs 0    # โ†’ "resize-image" (peek without removing)

Trimming and updating

# Keep only the last 100 items (rolling log)
LTRIM activity:feed 0 99

# Update an element by index
LSET jobs 0 "compress-image"

Blocking pop

# Wait up to 30 seconds for an item
BLPOP jobs 30

BLPOP blocks the client connection until an item arrives or the timeout expires. This turns Redis into a lightweight message queue without polling. A worker process calls BLPOP in a loop; a producer calls RPUSH. This is the foundation of many job-queue systems before dedicated tools like BullMQ.

Up next

Redis Set commands: SADD, SMEMBERS, SINTER, SUNION, SDIFF

Sign in to track progress

Redis List commands: LPUSH, RPUSH, LPOP, LRANGE, LLEN โ€” Core Commands and Data Structures โ€” Redis: Complete Course โ€” Script Valley โ€” Script Valley