Command: STR.APPEND
Overview
The STR.APPEND
command is used to append one or more string values to an existing string stored at a given key. If the key does not exist, it creates a new entry with the concatenated value.
Command Name
STR.APPEND
Description
Appends the provided string values to the end of the string currently stored at the specified key. If the key does not exist, a new string is created. If the existing value is not a string, an error is returned.
Use Cases
Append Logging Entries
You can use STR.APPEND
to build log-like string values that grow with each log message:
STR.APPEND log:serviceA "[INFO] Started"
STR.APPEND log:serviceA " [DEBUG] Listening on port 8080"
Construct Responses
Build dynamic string responses over time based on state or input:
STR.APPEND response:user42 "Hello "
STR.APPEND response:user42 "World"
Progressive Key Initialization
Initialize a new key and keep updating it in different steps:
STR.APPEND init:flow "Step1"
STR.APPEND init:flow " -> Step2"
Syntax
STR.APPEND <key> <value> [<value> ...]
-
<key>
: Required. The key of the existing or new string. -
<value>
: One or more strings to append.
Permissions
-
Read & Write access on the specified key.
-
Internal shard lookup is based on the key for distributed storage compatibility.
Input Examples
Append to a non-existent key
localhost:9219> STR.APPEND key1 "Hello"
Ok
Append to an existing key
localhost:9219> STR.APPEND key1 " World"
Ok
Append multiple values
localhost:9219> STR.APPEND key1 " and" " John"
Ok
Output Examples
After appending:
localhost:9219> GET key1
Ok "Hello World and John"
Behavior on Error
Error Condition | Message |
---|---|
No key provided | InvalidKeyError: Key must be provided |
Key name fails validation | InvalidKeyError: <validation reason> |
Value at key is not of type string |
InvalidValueError: the existing value for the provided key must be a string |
Storage backend error while setting the value | <error from store.M.Set> |