APPEND
The APPEND
command in DiceDB is used to either set the value of a key or append a value to an existing key and returns the length of the value stored at the specified key after appending. This command allows for both creating and updating key-value pairs.
Syntax
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
key | The name of the key to be set. | String | Yes |
value | The value to be set for the key. | String | Yes |
Return values
Condition | Return Value |
---|---|
if key is set successfully | length of the string. |
Behaviour
- If the specified key does not exist, the
APPEND
command will create a new key-value pair. - If the specified key already exists, the
APPEND
command will append the value to the existing value of the key.
Errors
-
Wrong type of value or key
:- Error Message:
(error) ERROR WRONGTYPE Operation against a key holding the wrong kind of value
- Occurs when attempting to use the command on a key that contains a non-string value.
- Error Message:
-
Invalid syntax or conflicting options
:- Error Message:
(error) ERROR wrong number of arguments for 'append' command
- If the number of arguments are not exactly equal to 2.
- Error Message:
Example Usage
Basic Usage
Setting a key foo
with the value bar
using APPEND
Appending to key foo
that contains bar
with baz
Appending “1” to key bmkey
that contains a bitmap equivalent of 42
Invalid usage
Trying to use APPEND
without giving the value
Trying to use APPEND
on a invalid data type.