Skip to main content

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:

bash
SET name "Ruslan" GET name

returns:

javascript
"Ruslan"

Typical usage scenarios

  1. Caching strings or JSON:
bash
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:

bash
INCR page_views INCRBY likes 5

The value gets converted and stored as a string automatically, but interpreted as a number. 3. Flags, tokens, temporary data

bash
SET auth_token "abc123" EX 600

Important commands for String

CommandPurpose
SET key valuewrites the value
GET keyreads the value
INCR key / DECR keyincrements/decrements a numeric value
APPEND key valueappends data to the end of the string
GETRANGE key start endgets a substring
MSET key1 val1 key2 val2 ...writes several at once
MGET key1 key2 ...reads several at once

An example as a counter

bash
INCR visits GET visits

Result:

javascript
(integer) 1 (integer) 2 (integer) 3

Summary

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 ready
Premium

A concise answer to help you respond confidently on this topic during an interview.