Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Redis Patterns?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/adityaaatiwari-redis-patterns)
---
name: redis-patterns
description: Use Redis correctly for caching, rate limits, locks, queues and sessions, with expiry and failure handling
---
<!-- Generated by `anvil plugin build` from catalog/. Edit the catalog, not this file. -->
# Redis patterns
Use when adding or changing Redis usage.
## Keys
- Namespace keys (`app:user:123:profile`) and give every cache key a TTL. Keys without expiry are a memory leak.
- Keep values small. Large blobs block the single-threaded server and the network.
- Avoid `KEYS *` in production; use `SCAN`.
## Caching
- Cache-aside: read Redis, fall back to the database, then set with a TTL. Invalidate on write, or use short TTLs where staleness is acceptable.
- Prevent stampedes: add jitter to TTLs and let one request recompute while others serve stale data or wait.
## Rate limiting
Use atomic operations: `INCR` with `EXPIRE` in a `MULTI`, or a Lua script for sliding windows. Never read-then-write from the client.
## Locks
`SET key token NX PX ttl` with a unique token. Release with a Lua script that deletes only if the token matches. Locks expire, so the protected work must be idempotent or fenced.
## Queues and streams
Use Streams with consumer groups (`XREADGROUP`, `XACK`) for at-least-once processing. Handle pending entries after crashes, and make consumers idempotent.
## Failure
- Treat Redis as optional for caches: time out fast and fall back to the source.
- Know the persistence settings before storing anything you cannot rebuild.
## Verify
Tests for cache hits, misses and invalidation; a concurrency test for locks and rate limits; check memory with `INFO memory` under load.