RPUSH
The RPUSH
command is used in DiceDB to insert one or multiple values at the tail (right end) of a list. If the list does not exist, it is created as an empty list before performing the push operations. This command is useful for maintaining a list of elements where new elements are added to the end of the list.
Syntax
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
key | The name of the list where values are inserted. If it does not exist, it will be created. | String | Yes |
value [value...] | One or more space separated values to be inserted at the tail of the list. | String | Yes |
Return Value
Condition | Return Value |
---|---|
Command is successful | Integer - length of the list after execution |
Syntax or specified constraints are invalid | error |
Behaviour
- When the
RPUSH
command is executed, the specified values are inserted at the tail of the list identified by the given key. - If the key does not exist, a new list is created and the values are inserted.
- If the key exists but is not a list, an error is returned.
- The
RPUSH
operation is atomic. If multiple clients issueRPUSH
commands concurrently, DiceDB ensures that the list remains consistent and the values are appended in the order the commands were received.
Errors
-
Wrong Number of Arguments
- Error Message:
(error) ERR wrong number of arguments for 'rpush' command
- Occurs if the key parameters is not provided or at least one value is not provided.
- Error Message:
-
Wrong Type of Key or Value
:- Error Message:
(error) WRONGTYPE Operation against a key holding the wrong kind of value
- Occurs if the key exists and is not a list. DiceDB expects the key to either be non-existent or to hold a list data type.
- Error Message:
Example Usage
Basic Usage
Inserting a value hello
into mylist
Inserting Multiple Values
Inserting multiple values world
, foo
, bar
into mylist
Invalid Usage: Key is Not a List
Insert the value value
at the tail of the key mystring
, which stores a string, not a list.
Invalid Usage: Wrong Number of Arguments
Calling RPUSH
without passing any values: