Redis Append Command

Redis String

The Redis APPEND command is used to append a value to a specified key.

If the key already exists and is a string, the APPEND command appends the value to the end of the key's original value.

If the key does not exist, APPEND simply sets the given key to value, just like executing SET key value.

Syntax

The basic syntax of the redis APPEND command is as follows:

redis 127.0.0.1:6379> APPEND KEY_NAME NEW_VALUE

Available Versions

>= 2.0.0

Return Value

The length of the string in the key after appending the specified value.

Example

# 对不存在的 key 执行 APPEND

redis> EXISTS myphone               # 确保 myphone 不存在
(integer) 0

redis> APPEND myphone "nokia"       # 对不存在的 key 进行 APPEND ,等同于 SET myphone "nokia"
(integer) 5                         # 字符长度


# 对已存在的字符串进行 APPEND

redis> APPEND myphone " - 1110"     # 长度从 5 个字符增加到 12 个字符
(integer) 12

redis> GET myphone
"nokia - 1110"

Redis String

Other Extensions