w3resource

Redis Lists: RPUSH

Redis RPUSH Command

Redis RPUSH command is used to insert all the specified values at the tail of the list stored at key. It is created as an empty list before performing the push operation if the key does not exist. An error is returned when key holds such a value that is not a list.

Here are some common uses and scenarios for the "RPUSH" command:

  • Queue Operations: Add elements to the end of a list to manage tasks or messages in a queue.
  • Event Handling: Append events or messages to the end of a list for immediate processing.
  • Data Processing Pipelines: Extend data pipelines by appending data to the end of a list for subsequent processing stages.
  • Task Management: Add tasks to the end of a task list for processing in the order they were received.

Syntax:

RPUSH KEY_NAME VALUE1..VALUEN

Available since

1.0.0.

Return Value

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

Return Value Type

Integer

Example: Redis RPUSH

127.0.0.1:6379> RPUSH mycolor1 white black
(integer) 2
127.0.0.1:6379> RPUSH mycolor1 red blue
(integer) 4
127.0.0.1:6379> LRANGE mycolor1 0 -1
1) "white"
2) "black"
3) "red"
4) "blue"

Previous: RPOPLPUSH
Next: RPUSHX



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/redis/redis-rpush-key-value1.php