Description
If key already exists and is a string, this command appends the value at the end of the string. If key does not exist, it is created and set as an empty string, so APPEND will be similar to SET in this special case.Syntax
Parameters
The key to append to
The string value to append
Returns
The length of the string after the append operation
Examples
Basic Usage
Building Strings Incrementally
Append to Non-Existent Key
Building CSV-like Data
Notes
- APPEND is very efficient for building strings incrementally
- The time complexity is O(1), assuming the appended value is small and the already present value is of any size
- If the key exists but is not a string, an error is returned
Related Commands
- set - Set the string value of a key
- get - Get the value of a key
- setrange - Overwrite part of a string at a specific offset
- getrange - Get a substring of the string stored at a key