0
0
Redisquery~5 mins

APPEND for string concatenation in Redis

Choose your learning style9 modes available
Introduction
APPEND lets you add more text to the end of a string stored in Redis without replacing the original text.
You want to build a message step-by-step in Redis.
You need to add new data to a log stored as a string.
You want to update a user's status message by adding more details.
You are collecting parts of a report and want to join them in Redis.
You want to keep adding notes to a string without losing old notes.
Syntax
Redis
APPEND key value
If the key does not exist, APPEND creates it with the given value.
APPEND returns the new length of the string after adding the value.
Examples
Adds "Hello" to the key 'greeting'. If 'greeting' does not exist, it creates it.
Redis
APPEND greeting "Hello"
Adds ", world!" to the existing 'greeting' string.
Redis
APPEND greeting ", world!"
Retrieves the full concatenated string stored in 'greeting'.
Redis
GET greeting
Sample Program
First, it adds "Hi" to 'message'. Then it adds ", how are you?" to the same key. Finally, it gets the full message.
Redis
APPEND message "Hi"
APPEND message ", how are you?"
GET message
OutputSuccess
Important Notes
APPEND works only with string values in Redis.
If you use APPEND on a key holding a different data type, Redis will return an error.
You can use APPEND multiple times to build a longer string gradually.
Summary
APPEND adds text to the end of a string in Redis without replacing it.
If the key does not exist, APPEND creates it with the new text.
APPEND returns the new length of the string after adding the text.