RPOP
RPOP key [count]
- Group
- List
- Complexity
- O(N) where N is the number of elements returned
- Arity
- -2 (at least 2 words, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
RPOP removes and returns the last element of the list stored at key. With
count, it removes and returns up to count elements from the tail, last
element first. When the list becomes empty, the key is deleted.
count must be a non-negative integer. A count of 0 returns an empty
array for an existing list. To wait for an element instead of getting nil, use
BRPOP.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
No count, list exists |
Bulk string: the popped element | Same |
No count, key does not exist |
Nil bulk string | Null |
With count, list exists |
Array of the popped elements | Same |
With count, key does not exist |
Nil array | Null |
Errors:
WRONGTYPEifkeyholds a value that is not a list.ERR value is out of range, must be positiveifcountis negative or not an integer.
Examples
Section titled “Examples”127.0.0.1:6379> RPUSH queue a b c d(integer) 4127.0.0.1:6379> RPOP queue"d"127.0.0.1:6379> RPOP queue 21) "c"2) "b"Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.