Back to Redis

RPOP

content/commands/rpop.md

latest2.2 KB
Original Source

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

By default, the command pops a single element from the end 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="rpop" description="Foundational: Remove and return the last element(s) from a list using RPOP (supports optional count parameter to pop multiple elements from tail)" difficulty="beginner" >}} redis> RPUSH mylist "one" "two" "three" "four" "five" (integer) 5 redis> RPOP mylist "five" redis> RPOP mylist 2

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

Give these commands a try in the interactive console:

{{% redis-cli %}} RPUSH mylist "one" "two" "three" "four" "five" RPOP mylist RPOP 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="rpop-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 last 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 last element.
  • Array reply: when called with the count argument, a list of popped elements.

{{< /multitabs >}}