Skip to content
Redis

Lists & Queues

Build queues and stacks with list operations.

By EZ4Code Team
listqueuestack

Code

# Push and pop from either end
LPUSH queue:email "job1" "job2"
RPUSH queue:email "job3"
LRANGE queue:email 0 -1

# FIFO queue (RPUSH + LPOP) and stack (LPUSH + RPOP)
LPOP queue:email
RPOP queue:email

# Blocking pop for worker queues
BLPOP queue:email 30     # blocks up to 30 seconds

# Trim to a capped log
LTRIM recent:logs 0 99

# Length and peek
LLEN queue:email
LINDEX queue:email 0

Explanation

Redis lists are linked lists of strings that support O(1) push/pop from both ends, making them ideal for queues and stacks. BLPOP blocks a worker until an item is available, avoiding polling. LTRIM keeps a list at a fixed length, useful for capping recent-activity logs.

More Redis Snippets