Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Command

LPOP

Removes and returns elements from the beginning of a Redis list. It removes one element by default or up to count elements when count is supplied.

Since
1.0.0

How it works

LPOP removes elements from the beginning of the list stored at the specified key and returns what it removed. Without count it removes one element; with count it removes up to that many elements, limited by the list length.

Syntax

LPOP key [count]

Parameters

NameTypeDescription
keykeyThe name of the key that holds the list.
countintegerThe maximum number of elements to pop; omitted means one.

Returns

Without count, a bulk string containing the first element, or nil if the key does not exist. With count, an array containing up to count elements, or nil if the key does not exist.

Key points

  • LPOP atomically removes values from the list head and returns those values.
  • Omitting count makes the command remove exactly one element when available.
  • With count, the result contains no more than the requested number of elements.
  • If fewer elements exist than requested, Redis returns only the elements present.
  • The required key argument identifies the list to modify.
  • The optional count argument controls the maximum number removed.
  • Runtime grows with the number of elements returned.

Common mistakes

  • When the final list element is removed, Redis deletes the key.
  • A nonexistent key returns a nil reply rather than an empty list.

Example: Pop list elements from the left

RPUSH tasks "build" "test" "deploy"
LPOP tasks
LPOP tasks 2

Adds three values, removes the oldest value, then removes up to two remaining values from the list.

When to use it

FIFO queue consumption

Consume queued work in insertion order by appending with RPUSH and removing with LPOP.

Stack-style processing

Use LPUSH and LPOP together when processing the newest item first.

Batch consumption

Remove several ready items in one command when batch size is bounded by count.

Interview questions

QWhat does LPOP do, and what does count change?

LPOP removes and returns the first element of a list. With count omitted it returns one bulk string; with count supplied it returns up to count elements.

Follow-up: How does the command behave when count exceeds the list length? It returns every remaining element, not an error.

QWhat is LPOP's time complexity?

The command operates on one list key and removes elements from its head. Its time complexity is O(N), where N is the number of elements returned.

Follow-up: What alternative supports multiple candidate keys? LMPOP can pop from the first non-empty list among supplied keys.

QWhat happens for a missing key or an emptied list?

If the key does not exist, LPOP returns a nil reply. If the last element is popped, Redis removes the list key.

Follow-up: How can a consumer wait for work instead of polling? BLPOP blocks the connection while the specified lists are empty.

  • BLPOP
  • LMPOP
  • LPUSH
  • LRANGE
  • RPOP

Source: LPOP | Docs. Checked 2026-10-16.