Redis is more than just a cache—it’s a powerful in-memory data store that supports real-time apps, queues, leaderboards, and more.
In this beginner-friendly guide, we’ll cover how to:
✅ Set up Redis locally or with Docker
✅ Use Redis CLI for quick testing
✅ Work with core data structures (Strings, Hashes, Lists, Sets, Sorted Sets)
🚀 Setup & Basics
Start Redis
Start Redis (local)
redis-server
Run with Docker
docker run --name redis -p 6379:6379 -d redis
Open Redis CLI
redis-cli
Test Connection
PING
# PONG
📦 Core Data Structures
🔹 Strings
SET name "Asad"
GET name
INCR counter
Use cases: counters, sessions, caching simple values.
Diagram:
key → value
----------------
name → "Asad"
counter → 1
🔹 Hashes
HSET user:1 name "Asad" age "25"
HGETALL user:1
Use cases: store JSON-like objects (e.g., user profiles).
Diagram:
user:1
├── name → "Asad"
└── age → "25"
🔹 Lists
LPUSH tasks "task1"
RPUSH tasks "task2"
LPOP tasks
Use cases: queues (FIFO), stacks (LIFO).
Diagram (FIFO Queue):
[ task1 ] → [ task2 ] → [ task3 ]
🔹 Sets
SADD tags "redis" "database" "cache"
SMEMBERS tags
Use cases: unique collections (tags, categories, followers).
Diagram:
tags = { "redis", "database", "cache" }
🔹 Sorted Sets
ZADD scores 100 "Asad" 200 "Plabon"
ZRANGE scores 0 -1 WITHSCORES
Use cases: leaderboards, rankings, priority queues.
Diagram:
+------+---------+
|User | Score |
+------+---------+
|Asad | 100 |
|Plabon| 200 |
✅ Wrap-Up
That’s the foundation of Redis. With just a few commands, you can build counters, queues, and ranking systems.
👉 In the next article, we’ll go deeper into advanced Redis concepts like Pub/Sub, Streams, persistence, clustering, and real-world AI use cases.
Top comments (0)