Suggest an editImprove this articleRefine the answer for “What is String in Redis?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)String in Redis is a sequence of bytes up to 512 megabytes long, which can hold plain text, a number, JSON, binary data, or even a compressed file; essentially it's a universal container for a value keyed by name, where the value is just a set of bytes. **Key point:** Redis can treat numeric strings as numbers via `INCR`/`INCRBY`, and String is the fundamental type that Redis's other structures (List, Hash, Set, etc.) are built on.Shown above the full answer for quick recall.Answer (EN)ImageIn 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 | 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 ```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.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.