Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
VGSources
Blog

How to Manage Lists in Redis: Commands, Patterns, and Safe Operations

A practical guide to Redis list management: choose the right end, build stacks and FIFO queues, inspect and trim data, move work between lists, and use blocking pops safely.
WorldRedis: Commands, Patterns, and Safe Operations Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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 LPUSH with LPOP.
  • Queue: append at one end and consume at the other. A common pairing is RPUSH with LPOP.
  • Deque: add or remove at either end as the workflow requires.
  • Bounded history: append new entries and use LTRIM to keep only the newest range.
  • Two-list handoff: use LMOVE to 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Finding 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keeping 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.

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 LRANGE cannot 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy 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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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 RPUSH plus LPOP for FIFO.
  • Use LLEN for point-in-time backlog measurements and LRANGE for 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 LMOVE when 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.