Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Command

RPUSH

Appends one or more values to the tail of a Redis list, creating the key when absent. It returns the list's new length.

Since
1.0.0

How it works

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.

Syntax

RPUSH key element [element ...]

Parameters

NameTypeDescription
keykeyThe name of the key that holds the list.
element [element ...]one or more valuesOne or more values to append to the list.

Returns

Integer reply: the length of the list after the push operation.

Key points

  • All supplied values are appended to the list's tail.
  • A missing key is initialized as an empty list before values are added.
  • One invocation can append multiple values.
  • Multiple arguments preserve their left-to-right order in the resulting list.
  • The response is the list's new length.

Common mistakes

  • The command fails if the key already contains a non-list value.
  • With multiple values, their command-line order becomes their list order.

Example: Append values and inspect the list

redis-cli RPUSH mylist "hello" "world"
redis-cli LRANGE mylist 0 -1

Appends two values, then reads the complete list to verify their order.

When to use it

Build an ordered list

Append events, jobs, or records while preserving insertion order.

Implement a queue

Add work at the tail and remove it from the head with LPOP or BLPOP.

Batch list appends

Add several related values in one command call.

Interview questions

QWhat does RPUSH do when its key does not exist?

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).

QExplain RPUSH's arguments and ordering.

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.

QWhat does RPUSH return, and when can it fail?

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.

  • LPUSH
  • RPUSHX
  • LPOP
  • RPOP
  • LRANGE

Source: RPUSH | Docs. Checked 2026-10-16.