0
0
Redisquery~5 mins

Redis data model (key-value)

Choose your learning style9 modes available
Introduction

Redis stores data as simple pairs of keys and values. This makes it very fast and easy to find information.

When you need to quickly save and get small pieces of data like user sessions.
When you want to count things like page views or clicks in real time.
When you need a simple cache to speed up your app by storing recent results.
When you want to store configuration settings that your app reads often.
When you need to share data between different parts of your system quickly.
Syntax
Redis
SET key value
GET key
The key is like a label or name for your data.
The value can be text, numbers, or more complex data types in Redis.
Examples
This saves the name "John Doe" under the key "user:1001" and then retrieves it.
Redis
SET user:1001 "John Doe"
GET user:1001
This stores the number 150 as the value for "page_views" and then gets it.
Redis
SET page_views 150
GET page_views
Sample Program

This example saves the status "active" for a session with ID "abc123" and then retrieves it.

Redis
SET session:abc123 "active"
GET session:abc123
OutputSuccess
Important Notes

Keys should be unique to avoid overwriting data.

Use meaningful key names to keep your data organized.

Redis values can be more than strings, but key-value is the simplest model.

Summary

Redis stores data as key-value pairs for fast access.

Keys are unique names; values hold the data.

This model is great for caching, sessions, and counters.