w3resource

Redis String: APPEND key value

Redis APPEND Command

Redis APPEND command is used to add some value in a key. If the 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,

Here are some common uses and scenarios for the "APPEND" command:

  • Concatenation: Append additional data to existing string values.
  • Log Management: Efficiently append data to log entries stored as strings.
  • Message Queues: Implement simple message queues by appending messages to a key.
  • Protocol Handling: Manage and update protocol-based data structures by appending data.
  • Efficient Data Storage: Append data to existing values without rewriting the entire string.

Syntax:

Basic syntax of redis APPEND command is shown below:

redis 127.0.0.1:6379> APPEND KEY_NAME NEW_VALUE

Available since

2.0.0.

Return Value

Integer reply, the length of the string after the append operation.

Return Value Type

Integer

Example:

redis 127.0.0.1:6379> SET mykey "hello"
OK
redis 127.0.0.1:6379> APPEND mykey "w3resource"
(integer) 20
redis 127.0.0.1:6379> GET mykey 
"hello tutorialspoint"

Previous: DECRBY
Next: Redis Hashes HDEL



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/redis/redis-append-key-value.php