What is String in Redis?
In Redis, String is the basic, simplest data type, and everything else is built on it. But despite the name, String in Redis isn't just text.
What a Redis String actually is
A Redis String is a sequence of bytes up to 512 megabytes long, which can hold:
- plain text (
"hello"), - a number (
"42"), - JSON, binary data, images, and even compressed files.
Essentially, it's a universal container for a value keyed by name, where the value is just a set of bytes.
What this looks like
An example command:
SET name "Ruslan"
GET namereturns:
"Ruslan"Typical usage scenarios
- Caching strings or JSON:
SET user:123 '{"name":"Anna","age":27}' EX 3600→ saves the user's data for 1 hour. 2. Counters and increments Redis can treat numeric strings as numbers:
INCR page_views
INCRBY likes 5The value gets converted and stored as a string automatically, but interpreted as a number. 3. Flags, tokens, temporary data
SET auth_token "abc123" EX 600Important commands for String
| Command | Purpose |
|---|---|
SET key value | writes the value |
GET key | reads the value |
INCR key / DECR key | increments/decrements a numeric value |
APPEND key value | appends data to the end of the string |
GETRANGE key start end | gets a substring |
MSET key1 val1 key2 val2 ... | writes several at once |
MGET key1 key2 ... | reads several at once |
An example as a counter
INCR visits
GET visitsResult:
(integer) 1
(integer) 2
(integer) 3Summary
String in Redis is a universal byte container. It can be:
- text, a number, JSON, a binary file,
- and used for caching, temporary flags, counters, tokens, and more.
It's the fundamental type that Redis's other structures (List, Hash, Set, etc.) are built on.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.