Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Module

APPEND

APPEND adds a string to the end of a key's existing string value, creating the key if it is missing. It returns the resulting string length.

Since
2.0.0

How it works

APPEND adds the supplied string to the existing string value at key. When the key is absent, Redis creates it with an empty starting value, then returns the resulting string length.

Syntax

APPEND key value

Parameters

NameTypeDescription
keykeyThe name of the key.
valuestringThe string to append to the existing value.

Returns

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

Key points

  • APPEND extends an existing Redis string by placing the supplied text at its end.
  • A missing key is initialized as an empty string before the supplied value is added.
  • The key argument identifies which string value Redis should modify.
  • The value argument supplies the text that Redis adds after the current contents.
  • The result is the updated string length, expressed as an integer reply.
  • For small appended fragments, repeated appends have amortized constant-time complexity.
  • Fixed-size samples can be concatenated into a compact string representation, such as a simple time series.

Common mistakes

  • The operation is amortized O(1) only when the appended fragment is small; this does not mean every append has constant cost for arbitrarily large input.

Example: Append fragments to a string

redis-cli <<'EOF'
DEL greeting
APPEND greeting "Hello"
APPEND greeting " world"
GET greeting
EOF

Creates the key on the first append, adds the second fragment, and reads the resulting string.

When to use it

Incremental string construction

Build a message or text buffer incrementally by adding fragments to one Redis string.

Compact fixed-size samples

Store fixed-width samples consecutively in one compact value for lightweight time-series data.

Interview questions

QWhat does APPEND do when the key does not exist?

APPEND takes a key and a string value, adding that value after the key's current string. If the key is missing, Redis creates it, and the command returns the string's length after modification.

Follow-up: What happens if the key contains a non-string value? The command requires a string value, so it cannot append to another Redis data type.

QWhat is the syntax and basic behavior of APPEND?

Its syntax is APPEND key value. The value is appended to the existing string, or used as the initial content of a newly created key.

Follow-up: How can a caller verify the resulting content? Use GET on the same key after APPEND, as in the documentation example.

QWhat does APPEND return, and what is its time complexity?

APPEND returns an integer equal to the length of the string after the append. Its amortized complexity is O(1) when the appended value is small, because Redis grows its dynamic string capacity efficiently.

Follow-up: Why is the complexity amortized rather than unconditionally constant? Reallocations can require additional work, especially as the stored string grows.

  • SET
  • GET

Source: Append. Checked 2026-10-16.