Redis Append command
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 value to the end of the key's existing value.
If the key does not exist, APPEND simply sets the given key to value, as if 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 Version
= 2.0.0
Return Value
The length of the string in the key after appending the specified value.
Example
# APPEND on non-existent key
redis> EXISTS myphone # 确保 myphone 不存在
(integer) 0
redis> APPEND myphone "nokia" # 对不存在的 key 进行 APPEND ,等同于 SET myphone "nokia"
(integer) 5 # 字符长度
# APPEND to an existing string
redis> APPEND myphone " - 1110" # 长度从 5 个字符增加到 12 个字符
(integer) 12
redis> GET myphone
"nokia - 1110"
Redis string