.claude/skills/redis/SKILL.md
Implements Redis for session storage, caching, rate limiting, and Bull job queues. Use when: implementing caching layers, session management, background jobs, rate limiting, pub/sub messaging, or idempotency keys for payment flows.
npx skillsauth add kaxuna1/ecomsite redisInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Redis session store, caching, and Bull job queues for Node.js/Express backends. This codebase currently uses in-memory solutions that should be replaced with Redis for production scalability and multi-instance deployments.
Detected: No ioredis, redis, or bullmq in backend dependencies.
Impact: Rate limiting and caching fail across multiple server instances.
cd backend
npm install ioredis bullmq
npm install -D @types/ioredis
// src/config/redis.ts
import Redis from 'ioredis';
const redis = new Redis({
host: process.env.REDIS_HOST || 'localhost',
port: parseInt(process.env.REDIS_PORT || '6379'),
password: process.env.REDIS_PASSWORD,
maxRetriesPerRequest: 3,
retryDelayOnFailover: 100,
enableReadyCheck: true,
});
redis.on('error', (err) => console.error('Redis error:', err));
redis.on('connect', () => console.log('Redis connected'));
export { redis };
// src/middleware/redisRateLimiter.ts
import { redis } from '../config/redis';
import { Request, Response, NextFunction } from 'express';
export async function redisRateLimiter(
key: string,
maxRequests: number,
windowMs: number
) {
return async (req: Request, res: Response, next: NextFunction) => {
const identifier = `ratelimit:${key}:${req.ip}`;
const current = await redis.incr(identifier);
if (current === 1) {
await redis.pexpire(identifier, windowMs);
}
if (current > maxRequests) {
const ttl = await redis.pttl(identifier);
res.setHeader('Retry-After', Math.ceil(ttl / 1000));
return res.status(429).json({ message: 'Too many requests' });
}
next();
};
}
| Concept | Usage | Example |
|---------|-------|---------|
| Caching | API response caching | redis.setex('products:list', 300, JSON.stringify(data)) |
| Rate Limiting | Request throttling | redis.incr() with pexpire() |
| Sessions | JWT token blacklist | redis.set('blacklist:token', '1', 'EX', 86400) |
| Job Queues | Background tasks | new Queue('emails', { connection: redis }) |
| Pub/Sub | Real-time events | redis.publish('order:created', orderId) |
When: Caching expensive database queries or API responses.
async function getProducts(lang: string): Promise<Product[]> {
const cacheKey = `products:${lang}`;
const cached = await redis.get(cacheKey);
if (cached) return JSON.parse(cached);
const products = await productService.getAll(lang);
await redis.setex(cacheKey, 300, JSON.stringify(products));
return products;
}
When: Data changes and cached values become stale.
async function updateProduct(id: number, data: ProductUpdate) {
await productService.update(id, data);
// Invalidate all product-related caches
const keys = await redis.keys('products:*');
if (keys.length) await redis.del(...keys);
}
tools
Zustand lightweight state management with persistence and middleware. Use when: managing client-side state (cart, auth, UI preferences), replacing React Context with simpler API, accessing state outside React components, implementing localStorage persistence
development
Zod schema validation and TypeScript integration for runtime type safety. Use when: Validating API payloads, form inputs, environment variables, or any external data boundaries where TypeScript types alone cannot guarantee safety.
tools
Configures Vite 5.x build tool, dev server, and frontend asset optimization for the Luxia e-commerce platform. Use when: configuring builds, adding environment variables, optimizing bundle size, setting up testing, debugging HMR issues, or adding Vite plugins.
development
Enforces strict TypeScript types across frontend and backend codebases. Use when: Writing new services, DTOs, interfaces, type guards, debugging type errors, or ensuring type safety at API boundaries.