LPUSH-&-RPUSH
Lists are ordered collections perfect for queues, stacks, and recent activity feeds. Push from either end, pop with blocking.
You'll Learn
- LPUSH, RPUSH, LPOP, RPOP syntax
- Viewing ranges with LRANGE
- Building queues and stacks
- How Redimo shows list index and order
See Your Data, Not Terminal Text
Redimo visualizes every Redis data type beautifully. Edit inline, undo mistakes, stay safe in production.
1. What Is a List?
A List is an ordered sequence of strings. You can push elements to the head (left) or tail (right), making it perfect for implementing queues, stacks, and timelines.
Lists maintain insertion order and allow duplicate values. They're implemented as linked lists, so pushing and popping from either end is O(1). Accessing by index is O(n), but Redis optimizes common patterns.
Syntax
LPUSH key value [value ...] # Push to head (left)
RPUSH key value [value ...] # Push to tail (right)
LPOP key [count] # Remove from head
RPOP key [count] # Remove from tail
LRANGE key start stop # Get range of elements
LLEN key # Get list length
LINDEX key index # Get element at index
LSET key index value # Set element at indexUnderstanding L and R
LPUSH adds to the left (head), RPUSH adds to the right (tail).LPOP removes from left, RPOP removes from right.
2. The CLI Way (Hard Mode)
Managing a job queue in CLI means lots of LRANGE commands and mental index tracking:
Building a Queue
127.0.0.1:6379> RPUSH jobs:pending "{\"id\":1,\"type\":\"email\",\"to\":\"user@test.com\"}"
(integer) 1
127.0.0.1:6379> RPUSH jobs:pending "{\"id\":2,\"type\":\"sms\",\"phone\":\"+1234567890\"}"
(integer) 2
127.0.0.1:6379> RPUSH jobs:pending "{\"id\":3,\"type\":\"push\",\"token\":\"abc123\"}"
(integer) 3
127.0.0.1:6379> LRANGE jobs:pending 0 -1
1) "{\"id\":1,\"type\":\"email\",\"to\":\"user@test.com\"}"
2) "{\"id\":2,\"type\":\"sms\",\"phone\":\"+1234567890\"}"
3) "{\"id\":3,\"type\":\"push\",\"token\":\"abc123\"}"Processing the Queue
127.0.0.1:6379> LPOP jobs:pending
"{\"id\":1,\"type\":\"email\",\"to\":\"user@test.com\"}"
127.0.0.1:6379> LLEN jobs:pending
(integer) 2
127.0.0.1:6379> LINDEX jobs:pending 0
"{\"id\":2,\"type\":\"sms\",\"phone\":\"+1234567890\"}"
127.0.0.1:6379> LRANGE jobs:pending 0 2
1) "{\"id\":2,\"type\":\"sms\",\"phone\":\"+1234567890\"}"
2) "{\"id\":3,\"type\":\"push\",\"token\":\"abc123\"}"The Problem
3. The Redimo Way (Smart Mode)
Redimo shows list elements with their index number, renders JSON beautifully, and lets you add items to head or tail with a single click.
What Redimo Does for Lists:
- ●Index Numbers: Every element shows its index. No counting required. Jump to any index instantly.
- ●JSON Expansion: JSON stored in list elements is rendered as expandable trees, just like String values.
- ●Head/Tail Buttons: Click "Add to Head" or "Add to Tail" to push new elements without remembering LPUSH vs RPUSH.
- ●Inline Editing: Click any element to edit it in place. LSET is called automatically.
- ●Delete by Index: Delete button on each row. No need to remember LREM syntax.
CLI Pain Points
- • No index numbers shown
- • JSON elements are unreadable
- • Must remember LPUSH vs RPUSH
- • LREM syntax is confusing
- • Can't see list length at a glance
Redimo Solutions
- • Clear index for every element
- • JSON expanded as tree view
- • "Add to Head/Tail" buttons
- • Delete button per element
- • Total count always visible
4. Queue vs Stack Patterns
Lists can implement both queues (FIFO) and stacks (LIFO) depending on which end you use:
Queue (FIFO)
First In, First Out - like a line at a store
RPUSH to add → LPOP to processStack (LIFO)
Last In, First Out - like a stack of plates
LPUSH to add → LPOP to processQueue Pattern (Job Queue)
# Producer adds jobs to the back
RPUSH jobs:email "{\"to\":\"user1@test.com\"}"
RPUSH jobs:email "{\"to\":\"user2@test.com\"}"
RPUSH jobs:email "{\"to\":\"user3@test.com\"}"
# Worker takes jobs from the front
LPOP jobs:email # Gets user1 (first added)
# Blocking pop (waits if queue is empty)
BLPOP jobs:email 30 # Wait up to 30 secondsStack Pattern (Undo History)
# Add actions to the stack
LPUSH history:user:1001 "{\"action\":\"delete\",\"key\":\"doc:123\"}"
LPUSH history:user:1001 "{\"action\":\"edit\",\"key\":\"doc:456\"}"
# Undo last action
LPOP history:user:1001 # Gets most recent action
# Peek without removing
LINDEX history:user:1001 05. Common Patterns
Recent Activity Feed
# Add new activity to the front
LPUSH activity:user:1001 "{\"type\":\"login\",\"time\":1703001234}"
LPUSH activity:user:1001 "{\"type\":\"purchase\",\"item\":\"Pro Plan\"}"
# Keep only last 100 activities
LTRIM activity:user:1001 0 99
# Get last 10 activities
LRANGE activity:user:1001 0 9Rate Limiting (Sliding Window)
# Record request timestamp
LPUSH requests:user:1001 1703001234
# Trim to window size (last 100 requests)
LTRIM requests:user:1001 0 99
# Count requests in last minute
# (would need Lua script for full implementation)
LLEN requests:user:10016. Pro Tips
Blocking Operations
Useful List Commands
# Get list length
LLEN mylist
# Edit element at index
LSET mylist 2 "new value"
# Remove specific value (count, key, value)
LREM mylist 0 "value to remove" # 0 = remove all occurrences
# Trim list to keep only recent items
LTRIM mylist 0 99 # Keep first 100
# Insert before/after element
LINSERT mylist BEFORE "pivot" "new value"
# Move element between lists atomically
LMOVE source destination LEFT RIGHTRedimo Bonus
Ready to Visualize?
Stop guessing list indices in your terminal.
Download Redimo and see your queues clearly.