LPUSH recent_activity 'user logged in'
RPUSH task_queue 'process order 123'
Topics
40
Caching Patterns
Cluster Sharding & Hash Slots
Clustering
Connection Pooling & Client Libraries
Data Types
Distributed Locks with Redis
Expiration & Eviction
Geospatial Data in Redis
Hashes in Redis
HyperLogLog in Redis
Keyspace Notifications
Leaderboards with Sorted Sets
Lists in Redis
Lua Scripting
Persistence (RDB/AOF)
Pub/Sub
Rate Limiting with Redis
Redis Architecture & Installation
Redis as a Message Queue
Redis Backup & Disaster Recovery
Redis CLI & Basic Commands
Redis Memory Optimization
Redis Modules Overview
Redis Monitoring & Observability
Redis Performance Tuning & Benchmarking
Redis Replication
Redis Security & ACL
Redis Sentinel & High Availability
Redis vs Memcached
Redis with Docker & Kubernetes
RedisBloom (Probabilistic Data Structures)
RedisJSON
RedisSearch (Full Text Search)
RedisTimeSeries
Session Management with Redis
Sets & Sorted Sets in Redis
Streams
Strings & Bitmaps in Redis
TLS & Encryption in Redis
Transactions
Lists in Redis
7 questions found
A Redis list is an ordered collection of values that maintains the order items were added, and you use LPUSH to add an item to the left, meaning the beginning, of the list, or RPUSH to add an item to the right, meaning the end, both operations being very fast regardless of how many items the list already contains.
Real-world example
A notification feed adds the newest notification to the beginning of a list using LPUSH, ensuring the most recent activity always appears first when the list is displayed.
Data Types;Redis as a Message Queue
You use the LRANGE command, specifying the list key along with a starting and ending index, which returns the items within that range without removing them from the list, letting you view a portion of the list's contents, such as the first ten items, as many times as needed.
LRANGE recent_activity 0 9
Real-world example
An activity feed displays the ten most recent items by calling LRANGE with a start index of zero and an end index of nine, leaving the underlying list completely unchanged.
Data Types;Redis CLI & Basic Commands
You use RPUSH to add new items to the end of the list, representing new work being added to the queue, and LPOP to remove and retrieve the item from the beginning of the list, representing the oldest item being processed next, together implementing a straightforward first in first out queue.
RPUSH task_queue 'task1'
RPUSH task_queue 'task2'
LPOP task_queue -- returns 'task1'
Real-world example
A background job processing system uses a Redis list as a simple task queue, adding new jobs with RPUSH and having worker processes continuously pull and process the oldest job with LPOP.
Redis as a Message Queue;Data Types
What does the BLPOP command do, and how is it useful for building a worker process that waits for new tasks?
IntermediateBLPOP works like LPOP but blocks and waits if the list is currently empty, up to a specified timeout, instead of immediately returning nothing, which lets a worker process efficiently wait for new work to arrive without needing to repeatedly poll an empty queue in a tight loop that wastes resources.
BLPOP task_queue 30 -- waits up to 30 seconds for a new task
Real-world example
A worker process waits efficiently using BLPOP for new tasks to arrive in the queue, immediately processing a task the moment one becomes available rather than constantly checking an empty queue every few milliseconds.
Redis as a Message Queue;Redis Performance Tuning & Benchmarking
How would you implement a reliable queue pattern using Redis lists that prevents losing a task if the worker processing it crashes?
AdvancedYou use the RPOPLPUSH or the newer LMOVE command to atomically move a task from the main queue into a separate processing list at the same time it is retrieved, so if a worker crashes while handling that task, it remains visible in the processing list and can be detected and reprocessed by a monitoring process, rather than being lost entirely.
RPOPLPUSH task_queue processing_queue
-- Worker processes the task, then removes it
-- from processing_queue only once fully complete
LREM processing_queue 1 'completed_task'
Real-world example
A payment processing system moves each task into a dedicated processing list as a worker picks it up, ensuring that if the worker crashes mid task, a monitoring process can detect the stuck task still sitting in the processing list and safely retry it.
Redis as a Message Queue;Distributed Locks with Redis
How does the internal encoding of Redis lists change as they grow, and what performance implications does this have?
AdvancedRedis stores small lists using a compact listpack encoding, similar to small hashes and sets, automatically switching to a doubly linked list structure called a quicklist once the list grows beyond a configurable size threshold, which trades some memory efficiency for better performance characteristics on larger lists with frequent additions and removals at both ends.
OBJECT ENCODING mylist
CONFIG GET list-max-listpack-size
Real-world example
A team storing many small activity log lists notices most of them stay within the compact listpack encoding threshold, keeping their overall memory usage lower than if every list had immediately switched to the larger quicklist structure.
Redis Memory Optimization;Data Types
How do you trim a Redis list to keep only a specific number of the most recent items, discarding older entries automatically?
IntermediateYou use the LTRIM command after adding a new item, specifying a range that keeps only the desired portion of the list, such as the most recent one hundred items, which is a common pattern for maintaining a bounded size activity feed or log without letting the list grow indefinitely and consume unlimited memory.
LPUSH recent_activity 'new event'
LTRIM recent_activity 0 99 -- keep only the most recent 100 items
Real-world example
A user activity feed pushes each new event to the front of a list and immediately trims it to keep only the hundred most recent entries, preventing the list from growing without bound over a user's entire history on the platform.
Redis Memory Optimization;Caching Patterns