Skip to content

APPEND

The APPEND command in DiceDB is used to either set the value of a key or append a value to an existing key. This command allows for both creating and updating key-value pairs.

Syntax

Terminal window
APPEND key value

Parameters

ParameterDescriptionTypeRequired
keyThe name of the key to be set.StringYes
valueThe value to be set for the key.StringYes

Return values

ConditionReturn Value
if key is set successfullylength 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

  1. 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.
  2. 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.

Example Usage

Basic Usage

Setting a key foo with the value bar using APPEND

Terminal window
127.0.0.1:7379> APPEND foo bar
(integer) 3

Appending to key foo that contains bar with baz

Terminal window
127.0.0.1:7379> SET foo bar
127.0.0.1:7379> APPEND foo baz
(integer) 6

Invalid usage

Trying to use APPEND without giving the value

Terminal window
127.0.0.1:7379> APPEND foo
(error) ERROR wrong number of arguments for 'append' command

Trying to use APPEND on a invalid data type.

Terminal window
127.0.0.1:7379> LPUSH foo bar
127.0.0.1:7379> APPEND foo baz
(error) ERROR WRONGTYPE Operation against a key holding the wrong kind of value