When most developers hear about Redis, they immediately think of it as a simple key-value store used for caching via SET
and GET
.
But Redis is so much more than that.
It’s a blazing-fast, in-memory data structure store packed with powerful features — like Lists, Hashes, Sorted Sets, Streams, Pub/Sub, and Key Expiry — that can drastically simplify backend development.
In this post, we'll explore Redis beyond just SET/GET with real-world use cases and examples to help you level up your usage.
🧵 1. Redis Lists – Built for Queues & Ordered Data
Lists in Redis are ordered sequences of strings. You can push or pop from either end, making them perfect for queues and stacks.
✅ Example: Job Queue System
LPUSH job_queue "send_welcome_email"
LPUSH job_queue "generate_invoice"
A background worker can consume jobs:
RPOP job_queue
# => "send_welcome_email"
🧠 LPUSH
+ RPOP
= FIFO Queue
📌 Ideal Use Cases:
- Background task queue
- Message queue between microservices
- Recent chat messages
- Activity logs
- To-do lists
🧮 2. Redis Hashes – Like Lightweight JSON Objects
Hashes let you store multiple key-value pairs under a single Redis key, much like storing a small object or database row.
✅ Example: User Profile Store
HSET user:1001 name "Arnav" age "25" role "admin"
HGET user:1001 name
# => "Arnav"
HGETALL user:1001
📌 Ideal Use Cases:
- User profiles (e.g.,
user:123
) - Shopping cart data
- App settings or preferences
- Product info (name, price, stock)
- Lightweight session data
🔢 3. Redis Sorted Sets – Rankings & Leaderboards
Sorted Sets (ZSET
) combine the uniqueness of Sets with the ability to sort elements by score.
✅ Example: Game Leaderboard
ZADD leaderboard 300 "player1"
ZADD leaderboard 450 "player2"
ZADD leaderboard 150 "player3"
ZREVRANGE leaderboard 0 2 WITHSCORES
📌 Ideal Use Cases:
- Game leaderboards
- Trending tags or posts
- Time-based activity tracking
- Job prioritization
- Scheduled task execution (score = timestamp)
📣 4. Redis Pub/Sub – Real-Time Messaging
Redis Pub/Sub allows for simple real-time communication. It works by publishing messages to channels that multiple subscribers can listen to.
✅ Example: Real-Time Notifications
# Terminal 1 (Subscriber)
SUBSCRIBE news_updates
# Terminal 2 (Publisher)
PUBLISH news_updates "🚨 New blog post is live!"
📌 Ideal Use Cases:
- Chat systems (channel-based messages)
- Real-time alerts or notifications
- Live dashboards (stock prices, analytics)
- Multiplayer game updates
- IoT device event broadcasting
⏱ 5. Key Expiry – Auto-Cleaning Your Data
Redis supports Time To Live (TTL) on any key, so it auto-deletes after a specified time.
✅ Example: OTP System
SET otp:login:123456 7890 EX 300 //
GET otp:login:123456
This key will expire after 300 seconds (5 minutes).
📌 Ideal Use Cases:
- OTPs and password reset codes
- Session tokens
- Cache invalidation
- API rate limiting
- Temporary promotions or trials
🧠 Bonus: Redis Has More Superpowers
Here are a few advanced features Redis supports:
- Bitmaps – Efficient user presence tracking
- HyperLogLogs – Approximate unique count tracking
- Streams – Kafka-like data streaming (for logs, events, etc.)
🔧 Quick Start: Using Redis with Node.js
Install the library:
npm install ioredis
Basic usage example:
const Redis = require("ioredis");
const redis = new Redis();
await redis.hset("user:1", "name", "Arnav", "age", "25");
const user = await redis.hgetall("user:1");
console.log(user); // { name: 'Arnav', age: '25' }
💡 Final Thoughts
Redis is much more than a caching layer.
It’s a powerful, real-time, in-memory database that can simplify many common backend challenges — queues, rankings, pub/sub systems, temporary data, and more.
If you're only using SET
and GET
, you’re missing out on 80% of Redis’s capabilities.
So go ahead and rediscover Redis. ❤️
Top comments (0)