Back to Redis

LPOP

content/commands/lpop.md

latest2.2 KB
Original Source

Removes and returns the first elements of the list stored at key.

By default, the command pops a single element from the beginning of the list. When provided with the optional count argument, the reply will consist of up to count elements, depending on the list's length.

Examples

{{< clients-example set="cmds_list" step="lpop" description="Foundational: Remove and return the first element(s) from a list using LPOP (supports optional count parameter to pop multiple elements)" difficulty="beginner" >}} redis> RPUSH mylist "one" "two" "three" "four" "five" (integer) 5 redis> LPOP mylist "one" redis> LPOP mylist 2

  1. "two"
  2. "three" redis> LRANGE mylist 0 -1
  3. "four"
  4. "five" {{< /clients-example>}}

Give these commands a try in the interactive console:

{{% redis-cli %}} RPUSH mylist "one" "two" "three" "four" "five" LPOP mylist LPOP mylist 2 LRANGE mylist 0 -1 {{% /redis-cli %}}

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | |

Return information

{{< multitabs id="lpop-return-info" tab1="RESP2" tab2="RESP3" >}}

One of the following:

  • Nil reply: if the key does not exist.
  • Bulk string reply: when called without the count argument, the value of the first element.
  • Array reply: when called with the count argument, a list of popped elements.

-tab-sep-

One of the following:

  • Null reply: if the key does not exist.
  • Bulk string reply: when called without the count argument, the value of the first element.
  • Array reply: when called with the count argument, a list of popped elements.

{{< /multitabs >}}