I'm always excited to collaborate on innovative and exciting projects!
Phone
Next.js • Python • UI/UX • Kayzi © 2024
Contact MeDate
Mon May 12 2025
Author
Dada Kayode

Redis didn’t just speed up my Next.js apps—it rewired how I build. From 800ms API responses to 12ms cache hits, real-time Pub/Sub, and stateless auth. Here’s how this cache became my secret weapon for scale.
That moment when you realize your Next.js apps have been running on "hard mode" without Redis:
1// pages/api/products.js
2export default async function handler(req, res) {
3 const cached = await client.get('products');
4 if (cached) return res.json(JSON.parse(cached));
5
6 const data = await fetchProducts(); // Expensive DB call
7 await client.setEx('products', 3600, JSON.stringify(data)); // 1-hour cache
8 res.json(data);
9}1// auth.js (JWT + Redis)
2export async function createSession(user) {
3 const token = jwt.sign({ id: user.id }, secret);
4 await client.set(`user:${user.id}`, token, { EX: 86400 }); // 1-day expiry
5 return token;
6}No more: ❌ Cookie theft vulnerabilities ❌ Database hits on every request
1// server.js
2const subscriber = client.duplicate();
3await subscriber.subscribe('orders', (message) => {
4 io.emit('new_order', message); // WebSocket broadcast
5});Use cases:
1npm install redis @upstash/redis # For Vercel/Serverless1// lib/redis.js
2import { createClient } from 'redis';
3
4export const client = createClient({
5 url: process.env.REDIS_URL
6});
7
8client.on('error', (err) => console.log('Redis error', err));
9await client.connect();Q: Redis vs. Vercel Edge Cache? A: Redis wins for dynamic data + advanced patterns like queues.
Q: Learning curve? A: ~2 days to basics, 2 weeks for advanced patterns.
Q: Cold starts? A: Use Upstash’s always-hot Redis for serverless.
Twitter Post:
"And it’s not even just caching... session management, rate limiting, Pub/Sub for real-time updates? Ah! This thing na full package." - @KayziGucci