Build an ordered list
Append events, jobs, or records while preserving insertion order.
Redis · Command
Appends one or more values to the tail of a Redis list, creating the key when absent. It returns the list's new length.
RPUSH appends every supplied element to the right-hand end of the list at key. Redis creates the key as a list when it is absent; arguments are added from left to right, and a non-list value causes an error. The command returns the resulting list length.
RPUSH key element [element ...]| Name | Type | Description |
|---|---|---|
key | key | The name of the key that holds the list. |
element [element ...] | one or more values | One or more values to append to the list. |
Integer reply: the length of the list after the push operation.
redis-cli RPUSH mylist "hello" "world"
redis-cli LRANGE mylist 0 -1Appends two values, then reads the complete list to verify their order.
Append events, jobs, or records while preserving insertion order.
Add work at the tail and remove it from the head with LPOP or BLPOP.
Add several related values in one command call.
RPUSH adds one or more values at the tail of a Redis list and returns the list length after the operation. If the key is missing, Redis creates the list first.
Follow-up: How does a multi-element call affect complexity? Each added element takes constant time, so adding N elements in one call is O(N).
The syntax is RPUSH key element [element ...]. key identifies the list, while the variadic element portion supplies one or more values to append.
Follow-up: What ordering results from RPUSH mylist a b c? The list contains a, then b, then c, because values are appended left to right.
The command returns an integer representing the list's length after the push. A key containing a non-list value produces an error instead of being converted.
Follow-up: Which command appends only when the list already exists? RPUSHX provides that conditional behavior.
LPUSHRPUSHXLPOPRPOPLRANGE