0
0
Redisquery~5 mins

Why strings are Redis's simplest type

Choose your learning style9 modes available
Introduction

Strings in Redis are the simplest type because they store plain text or binary data directly. They are easy to use and fast to read or write.

Storing user names or simple text values.
Caching small pieces of data like tokens or flags.
Counting things by storing numbers as strings.
Saving short messages or status information.
Syntax
Redis
SET key value
GET key

SET stores a string value under a key.

GET retrieves the string value stored at a key.

Examples
Stores the text "Hello, Redis!" and then retrieves it.
Redis
SET greeting "Hello, Redis!"
GET greeting
Stores the number 100 as a string and retrieves it.
Redis
SET counter 100
GET counter
Stores the word "true" as a string and retrieves it.
Redis
SET flag true
GET flag
Sample Program

This example saves the string "blue" under the key "favorite_color" and then gets it back.

Redis
SET favorite_color blue
GET favorite_color
OutputSuccess
Important Notes

Strings in Redis can hold any data up to 512 MB in size.

Even numbers are stored as strings, so you can use string commands or numeric commands on them.

Summary

Redis strings are simple and store plain text or binary data.

They are easy to set and get with simple commands.

Strings are useful for many common tasks like caching and counting.