Manage a Redis list by choosing an end, an operation, and a consumption style. LPUSH and RPUSH add values at the head or tail; LPOP and RPOP remove them; LRANGE reads without removing; and LLEN reports the current length. Combining opposite ends gives you a stack, queue, work queue, or two-list pipeline.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
Use indexed commands only when you need positional access, because middle indexes are linear-time. Use LTRIM to retain a bounded window, LMOVE to transfer an item between lists, and blocking pops such as BLPOP when a consumer should wait instead of polling. Check the command page for your server version before adopting newer features such as LMOVEM.
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
Redis in Action | $32.95 | Buy on Amazon |
| 2 |
|
Redis in Action Introduction and Python Integration | $18.00 | Buy on Amazon |
| 3 |
|
Redis with AI: A Complete Beginner's Guide to Redis, Caching, Real-Time Systems, and AI-Powered Data... | $18.00 | Buy on Amazon |
| 4 |
|
Grails in Action | $39.66 | Buy on Amazon |
| 5 |
|
Spring in Action, Fourth Edition: Covers Spring 4 | $19.99 | Buy on Amazon |
As an Amazon Associate I earn from qualifying purchases.
Recommended Free Tools
What a Redis list is and why the ends matter
A Redis list is an ordered sequence of elements stored under one key. Every value has a position, and the sequence has two addressable ends: the head (the left side) and the tail (the right side). List commands are designed around those ends, so the same data type can implement several common behaviors without changing its representation.
- Stack: push and pop on the same end. For example, pair
LPUSHwithLPOP. - Queue: append at one end and consume at the other. A common pairing is
RPUSHwithLPOP. - Deque: add or remove at either end as the workflow requires.
- Bounded history: append new entries and use
LTRIMto keep only the newest range. - Two-list handoff: use
LMOVEto pop from one list and push to another in one operation.
The direction is part of the design. Decide which end producers use and which end consumers use before writing application code; otherwise, reversing one command can silently reverse processing order.
#1 Best Overall
Adding elements with LPUSH and RPUSH
LPUSH: insert at the head
LPUSH key element [element ...] inserts one or more elements at the head of the list. Each new element becomes the leftmost value, so repeated pushes place the newest pushed value first when you inspect the list from left to right.
LPUSH tasks "compile" "test"
After this command, the list is ordered with test before compile, because the command processes the supplied values into the head position. Use this direction when newest-first behavior is intentional, such as a simple stack or a feed where the latest event should be read first.
RPUSH: append at the tail
RPUSH key element [element ...] appends values at the tail. Redis creates the key when it does not already exist, which makes RPUSH convenient for starting a queue with the first item.
RPUSH tasks "compile" "test"
Here, compile remains before test. A producer that always uses RPUSH preserves arrival order for a consumer that removes from the head with LPOP.
Choosing the push direction
| Goal | Add command | Typical remove command | Resulting order |
|---|---|---|---|
| Newest item first | LPUSH |
LPOP |
Last pushed item is consumed first |
| First-in, first-out queue | RPUSH |
LPOP |
Oldest appended item is consumed first |
| Tail-oriented stack | RPUSH |
RPOP |
Last appended item is consumed first |
When a command accepts multiple elements, verify the resulting order with LRANGE key 0 -1 during development. This catches an accidental left-versus-right choice before it affects production processing.
Removing elements with LPOP and RPOP
LPOP: remove from the head
LPOP key removes an element from the head, the same side used by LPUSH. It is the usual consumer operation for a queue built with RPUSH. Removal changes the list, so a subsequent read no longer includes the popped value.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
RPOP: remove from the tail
RPOP key removes an element from the tail. Pairing it with LPUSH or RPUSH lets you choose whether the newest or oldest item is consumed first.
RPUSH jobs "a" "b" "c"
LPOP jobs
RPOP jobs
The first pop takes the head item, while the second takes whatever is then at the tail. Keep producers and consumers consistent: mixing directions can be useful for a deque, but it is a common source of unexpected order in a queue.
When popping is not enough
Use a pop when you want to consume one end item immediately. Use LTRIM when you want to retain a range and discard everything outside it, or LREM when deletion is based on value rather than position. Use BLPOP or BRPOP when an empty list should make a consumer wait instead of returning immediately.
Reading lists without changing them
LRANGE for a window of elements
LRANGE key start stop returns the requested inclusive range without removing anything. Offset 0 is the head, and negative offsets count backward from the tail; -1 therefore identifies the last element.
Free tools Windows power users keep installed
One-click scans. No signup required.
LRANGE jobs 0 -1
LRANGE jobs 0 9
LRANGE jobs -10 -1
The first command reads the whole list, the second reads the first ten positions, and the third reads the last ten positions when that many exist. Because the range is inclusive, a request from 0 through 9 contains ten positions.
Redis documents LRANGE as O(S+N), where S is the distance of the start offset from the nearest end and N is the number of elements returned. A small range near either end is therefore a better fit than repeatedly asking for a large middle slice.
LLEN for the current length
LLEN key returns the number of elements in the list. Its complexity is O(1), so checking length does not require scanning every value.
LLEN jobs
Use the result for dashboards, admission checks, or a producer-side signal that a backlog is growing. Length is a point-in-time observation; another client can push or pop immediately after the command returns.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Index access with LINDEX and LSET
LINDEX: read one position
LINDEX key index reads the element at a specific zero-based index without removing it. Index 0 is the head, index -1 is the tail, and other negative indexes count backward from the end.
LINDEX jobs 0
LINDEX jobs -1
LINDEX jobs 3
LINDEX is O(N) in general, but it is O(1) for the first or last element. Treat frequent middle-index lookups as a sign that a list may not be the right access pattern; reading a known range or maintaining a separate lookup structure can avoid repeated linear walks, but those alternatives are outside the list commands themselves.
Rank #3
LSET: replace one position
LSET key index element replaces the value at an existing index. It has the same complexity profile as LINDEX: O(N) generally and O(1) at the first or last element.
LSET jobs 0 "priority-job"
Use LSET for an intentional in-place correction, not as a substitute for consuming work. A consumer that needs to claim an item should use a pop or a move operation so that removal and handoff semantics match the workflow.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallFinding and removing values
LPOS: locate matching elements
LPOS key element [RANK rank] [COUNT num-matches] [MAXLEN len] searches for positions containing a value. The optional arguments let you select a rank, request multiple matches, or limit the search to a maximum length.
LPOS jobs "compile"
LPOS jobs "compile" COUNT 3
LPOS jobs "compile" MAXLEN 100
Use the returned position with LINDEX when you need to inspect the matching value, or with LSET when replacing that position is the desired operation. Searching and then changing the list are separate commands, so another client can modify the list between them.
LREM: remove by value
LREM removes elements that match a specified value. It is the value-based removal path, unlike LPOP and RPOP, which always remove an end element. If the last element is removed, Redis deletes the list itself.
Use LREM for cleanup of duplicate markers, cancellation tokens, or stale entries when you know the stored value. Do not use it when position or arrival order is the real requirement; an end pop expresses that intent more directly.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteKeeping a bounded list with LTRIM
LTRIM key start stop keeps only the specified inclusive range and removes everything outside it. Negative offsets count from the tail, with -1 as the last element. Redis documents the complexity as O(N), where N is the number of elements removed.
Retaining the newest entries
RPUSH recent "event-1" "event-2" "event-3" "event-4"
LTRIM recent -3 -1
LRANGE recent 0 -1
The trim keeps the final three positions and discards older entries. This pattern is useful for bounded recent-event lists, provided the application can tolerate older events being removed permanently.
Rank #4
Trim timing and safety
- Append first, then trim, so the newly written item is eligible for retention.
- Choose the range from the retention rule, not from a guessed byte size; list elements can have different lengths.
- Remember that trimming is destructive. Once an element is outside the kept range, a later
LRANGEcannot recover it. - Account for the removal cost when a single trim discards a very large number of elements.
Moving work between lists with LMOVE
LMOVE source destination <LEFT | RIGHT> <LEFT | RIGHT> pops an item from one end of the source list and pushes it to one end of the destination list. The two direction arguments independently select the source side and destination side.
LMOVE pending processing LEFT RIGHT
This transfers the head of pending to the tail of processing. It is useful for separating ready work from in-progress work while preserving an explicit handoff step.
LMOVE version compatibility
The lists documentation and the LMOVE page identify version 6.2.0 as the introduction point. A Redis 8.8 command reference surfaced in the available material lists 1.0.0 instead, so the sources conflict. Treat 6.2.0 as the better-supported compatibility marker and verify the exact command page for the Redis version running in your environment before deployment.
LMOVEM on recent servers
The lists documentation describes LMOVEM as introduced in 8.10.0. That makes it a recent-server feature rather than a generally portable command. Check the server version and the version selector on the command documentation before using it in code that may connect to older Redis installations.
Blocking consumers with BLPOP and BRPOP
BLPOP behavior
BLPOP key [key ...] timeout waits for an element from the first non-empty list among the keys supplied. Redis checks the keys in the order given. A timeout of 0 waits indefinitely.
BLPOP high_priority normal_priority 30
This asks Redis to check high_priority before normal_priority and wait up to the specified timeout if both are empty. Ordering the key arguments is therefore part of the priority policy.
BRPOP behavior
BRPOP is the blocking counterpart for removing from the tail. Like BLPOP, it blocks the connection until an eligible list receives an item or the timeout is reached. The Redis glossary describes both commands as blocking until a timeout occurs or another client pushes a value.
Blocking versus polling
| Requirement | Use | Connection behavior |
|---|---|---|
| Return immediately, even when empty | LPOP or RPOP |
Non-blocking removal |
| Wait for work from one or more lists | BLPOP |
Blocks until a list has an item or the timeout expires |
| Wait while consuming from the tails | BRPOP |
Blocks until a list has an item or the timeout expires |
A blocking command occupies its connection while waiting. Give workers dedicated connections or use a client configuration that supports blocking operations without starving unrelated commands. A timeout of zero is appropriate only when an indefinitely waiting worker is intentional and the client can close the connection cleanly during shutdown.
Best Value
A practical queue workflow
1. Create the queue
RPUSH jobs "job-001" "job-002" "job-003"
Using RPUSH establishes arrival order and creates the key if it does not exist.
2. Inspect backlog and sample entries
LLEN jobs
LRANGE jobs 0 4
LLEN gives the current count, while the range command samples the head of the queue without consuming work.
3. Consume immediately or wait
LPOP jobs
BLPOP jobs 30
Use the first form for a worker that already has a polling loop. Use the second when the worker should sleep inside Redis until work arrives or 30 seconds elapse.
4. Move claimed work
LMOVE jobs in_progress LEFT RIGHT
The move records a handoff to a separate list. The command still does not provide an acknowledgement protocol by itself; the application must decide how and when an item leaves in_progress.
5. Apply retention deliberately
LTRIM completed -1000 -1
Use a trim only when discarding entries older than the retained range is acceptable.
Complexity and command selection
| Command | Purpose | Documented complexity or behavior |
|---|---|---|
LPUSH |
Insert at head | End insertion |
RPUSH |
Append at tail and create a missing key | End insertion |
LPOP, RPOP |
Remove from head or tail | End removal |
LRANGE |
Read an inclusive range | O(S+N) |
LLEN |
Read list length | O(1) |
LINDEX |
Read one index | O(N), O(1) at first or last element |
LSET |
Replace one index | O(N), O(1) at first or last element |
LPOS |
Search for matching values | Supports rank, count, and maximum-length limits |
LREM |
Remove matching values | Deletes the list if its last element is removed |
LTRIM |
Keep only a range | O(N), where N is the number removed |
LMOVE |
Pop one list end and push to another | Source and destination ends are selectable |
BLPOP, BRPOP |
Blocking end removal | Wait for a push or timeout; timeout 0 waits indefinitely |
The practical rule is simple: stay at the ends for queue and stack workloads, use ranges for bounded reads, and reserve indexed or value searches for occasional inspection and maintenance.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Common failure modes and fixes
Items appear in reverse order
Check whether the producer uses LPUSH when you intended append semantics, or whether the consumer uses RPOP instead of LPOP. Read the full list with LRANGE key 0 -1 and document the intended producer-consumer pair.
A worker spins when the queue is empty
Replace a tight loop around LPOP with BLPOP or BRPOP. Choose a finite timeout when the worker needs periodic housekeeping; use timeout 0 only for an intentionally indefinite wait.
Middle-index operations become slow
LINDEX and LSET are linear-time away from the ends. Rework the access pattern toward end operations or range reads, and avoid treating a list as a random-access table.
History grows without limit
Append the new record, then apply LTRIM with a range that retains the desired number of newest entries. Make the destructive retention policy explicit to anyone consuming the list.
A command works in one environment but not another
Redis documentation provides version selectors including 8.10, 8.4, 8.0, 7.4, 7.2, and 6.2. Select the server version on each command page before relying on newer syntax, especially LMOVE and LMOVEM. The documented introduction information for LMOVE is inconsistent, so confirm it against the exact version you operate.
Quick Recap
A checklist for production list designs
- Write down which side is the head and which side is the tail in your application terminology.
- Choose a producer-consumer pair such as
RPUSHplusLPOPfor FIFO. - Use
LLENfor point-in-time backlog measurements andLRANGEfor non-destructive inspection. - Keep indexed operations near the ends; middle access is O(N).
- Use blocking pops for wait-based workers and dedicate a connection to the blocking call.
- Use
LMOVEwhen an item must leave one list and enter another in the same operation. - Trim only when discarded history is no longer needed.
- Confirm command availability with the Redis version selector before deployment.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




