Learn production-ready Redis patterns for caching, concurrency, and messaging.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "redis-patterns" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/redis-patterns/SKILL.md 2. Save it as ~/.claude/skills/redis-patterns/SKILL.md 3. Reload skills and tell me it's ready
Design a Redis caching strategy for a high-concurrency e-commerce product detail service, including key design, TTL strategy, protection against cache penetration/breakdown/avalanche, fallback flow after expiration, and sample code.
A practical Redis caching architecture with key naming rules, expiration strategy, and sample code.
Explain how to implement a safe distributed lock with Redis, including lock acquisition, renewal, release, accidental deletion prevention, and considerations for multi-instance deployment, with Java or Node.js examples.
An implementation approach for distributed locks, risk explanations, and directly usable sample code.
Design a Redis-based API rate limiting and Pub/Sub notification solution, and explain the use cases, core data structures, performance considerations, and connection management best practices.
A comparison of rate limiting and messaging approaches, implementation guidance, and production connection management tips.
Quick reference for Redis best practices across common backend use cases.
Redis is an in-memory data structure store that supports strings, hashes, lists, sets, sorted sets, streams, and more. Individual Redis commands are atomic on a single instance; multi-step workflows require Lua scripts, MULTI/EXEC transactions, or explicit synchronization to stay atomic. Data is optionally persisted via RDB snapshots or AOF logs. Clients communicate over TCP using the RESP protocol; connection pools are essential to avoid per-request handshake overhead.
| Use Case | Structure | Example Key |
|---|---|---|
| Simple cache | String | product:123 |
| User session | Hash | session:abc |
| Leaderboard | Sorted Set | scores:weekly |
| Unique visitors | Set | visitors:2024-01-01 |
| Activity feed | List | feed:user:456 |
| Event stream | Stream | events:orders |
| Counters / rate limits | String (INCR) | ratelimit:user:123 |
| Bloom filter / HLL | HyperLogLog | hll:pageviews |
import redis
import json
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
def get_product(product_id: int):
cache_key = f"product:{product_id}"
cached = r.get(cache_key)
if cached:
return json.loads(cached)
product = db.query("SELECT * FROM products WHERE id = %s", product_id)
r.setex(cache_key, 3600, json.dumps(product)) # TTL: 1 hour
return product
def update_product(product_id: int, data: dict):
# Write to DB first
db.execute("UPDATE products SET ... WHERE id = %s", product_id)
# Immediately update cache
cache_key = f"product:{product_id}"
r.setex(cache_key, 3600, json.dumps(data))
# Tag-based invalidation — group related keys under a set
def cache_product(product_id: int, category_id: int, data: dict):
key = f"product:{product_id}"
tag = f"tag:category:{category_id}"
pipe = r.pipeline(transaction=True)
pipe.setex(key, 3600, json.dumps(data))
pipe.sadd(tag, key)
pipe.expire(tag, 3600)
pipe.execute()
def invalidate_category(category_id: int):
tag = f"tag:category:{category_id}"
keys = r.smembers(tag)
if keys:
r.delete(*keys)
r.delete(tag)
import time
import uuid
def create_session(user_id: int, ttl: int = 86400) -> str:
session_id = str(uuid.uuid4())
key = f"session:{session_id}"
pipe = r.pipeline(transaction=True)
pipe.hset(key, mapping={
"user_id": user_id,
"created_at": int(time.time()),
})
pipe.expire(key, ttl)
pipe.execute()
return session_id
def get_session(session_id: str) -> dict | None:
data = r.hgetall(f"session:{session_id}")
return data if data else None
def delete_session(session_id: str):
r.delete(f"session:{session_id}")
def is_rate_limited(user_id: int, limit: int = 100, window: int = 60) -> bool:
key = f"ratelimit:{user_id}:{int(time.time()) // window}"
pipe = r.pipeline(transaction=True)
pipe.incr(key)
pipe.expire(key, window)
count, _ = pipe.execute()
return count > limit
-- sliding_window.lua
local key = KEYS[1]
local now = tonumber(ARGV[1])
local window = tonumber(ARGV[2])
local limit = tonumber(ARGV[3])
redis.call('ZREMRANGEBYSCORE', key, 0, now - window)
local count = redis.call('ZCARD', key)
if count < limit then
…
Plan demand forecasts, safety stock, and replenishment for multi-location retail inventory.
Automatically format, lint, and fix code issues on every edit.
Apply NestJS architecture patterns to build maintainable production-ready TypeScript backends.
Learn robust error-handling patterns across TypeScript, Python, and Go applications.
Audit Claude skills and commands with quick scans or full stocktakes.
Create iOS liquid glass interfaces with dynamic visuals and interactive morphing.
Learn Django architecture, DRF API design, and production-ready development practices.
Get production-ready MySQL and MariaDB schema, query, and operations patterns.
Learn Laravel production architecture patterns and core backend implementation practices.
Safely inspect and diagnose Redis instances with read-only key exploration.
Learn idiomatic Rust patterns, ownership, concurrency, and robust error handling practices.
Learn production-grade Kubernetes patterns, access control, scaling, and debugging workflows.