FIFO queue consumption
Consume queued work in insertion order by appending with RPUSH and removing with LPOP.
Redis · Command
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.
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.
LPOP key [count]| Name | Type | Description |
|---|---|---|
key | key | The name of the key that holds the list. |
count | integer | The maximum number of elements to pop; omitted means one. |
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.
RPUSH tasks "build" "test" "deploy"
LPOP tasks
LPOP tasks 2Adds three values, removes the oldest value, then removes up to two remaining values from the list.
Consume queued work in insertion order by appending with RPUSH and removing with LPOP.
Use LPUSH and LPOP together when processing the newest item first.
Remove several ready items in one command when batch size is bounded by count.
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.
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.
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.
BLPOPLMPOPLPUSHLRANGERPOP