DEV Community

Cover image for Redis Basics – Getting Started and Core Data Structures
Md Asaduzzaman
Md Asaduzzaman

Posted on

Redis Basics – Getting Started and Core Data Structures

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
Enter fullscreen mode Exit fullscreen mode

📦 Core Data Structures
🔹 Strings

SET name "Asad"
GET name
INCR counter
Enter fullscreen mode Exit fullscreen mode

Use cases: counters, sessions, caching simple values.

Diagram:

key    →   value
----------------
name   →   "Asad"
counter →   1
Enter fullscreen mode Exit fullscreen mode

🔹 Hashes

HSET user:1 name "Asad" age "25"
HGETALL user:1
Enter fullscreen mode Exit fullscreen mode

Use cases: store JSON-like objects (e.g., user profiles).

Diagram:

user:1
 ├── name → "Asad"
 └── age  → "25"
Enter fullscreen mode Exit fullscreen mode

🔹 Lists

LPUSH tasks "task1"
RPUSH tasks "task2"
LPOP tasks
Enter fullscreen mode Exit fullscreen mode

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)