Redis Patterns Library
Caching strategies, pub/sub patterns, rate limiting, session management, and Redis cluster configuration templates.
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 26 files
📖 Documentation Preview README excerpt
Redis Patterns Library
A working reference for the Redis usage patterns that show up again and again in
real systems: caching, rate limiting, distributed locks, pub/sub, streams, and
sorted-set leaderboards — plus the memory and eviction tuning that keeps them
healthy under load.
Every pattern here is paired with runnable artifacts, not pseudocode:
- Atomic Lua scripts you can
EVALdirectly (rate limiter, sliding window,
lock acquire/release) — atomicity is the whole point, and Lua is how you get it.
redis-cliwalkthroughs (scripts/*.sh) that you can paste line by line to
watch a pattern behave.
- Dependency-free Python (
examples/*.py) built on a tiny RESP client that
speaks the Redis wire protocol over a plain socket — no pip install required.
- An annotated
redis.confthat explains why each tuning knob matters, not
just what it is set to.
Who this is for
Backend and platform engineers who already run Redis (or are about to) and want
correct, copy-pasteable implementations of the patterns that are easy to get
subtly wrong: locks that release someone else's lock, rate limiters that leak
under concurrency, caches that stampede a cold key, and streams consumer groups
that lose messages on crash.
Prerequisites
- Redis 6.2+ (7.x recommended). Streams require 5.0+,
GETDELrequires 6.2+,
and the eviction notes assume the 7.x maxmemory policies. Where a feature
needs a newer server, the doc says so.
redis-clion yourPATHfor the shell walkthroughs.- Python 3.10+ for the
examples/scripts. They use only the standard
library — socket, time, hashlib, uuid. There is nothing to install.
- A Redis instance you can talk to. Everything defaults to
127.0.0.1:6379;
override with the REDIS_HOST / REDIS_PORT environment variables.
Hostnames such as cache01.example.com throughout the docs are placeholders.
Replace them with your own. No real infrastructure, addresses, or credentials
appear anywhere in this product.
How to run
# 1. Point at your Redis (defaults shown)
export REDIS_HOST=127.0.0.1
export REDIS_PORT=6379
# 2. Load the annotated config (optional, for a local test server)
redis-server config/redis.conf
# 3. Watch a pattern behave, line by line
bash scripts/cache_aside_demo.sh
bash scripts/leaderboard_demo.sh
bash scripts/streams_consumer_group.sh
# 4. Run an atomic Lua script straight from the file
redis-cli --eval lua/sliding_window.lua ratelimit:user:42 , "$(date +%s%3N)" 60000 5 "req-$RANDOM"
# 5. Run the dependency-free Python examples
*... continues with setup instructions, usage examples, and more.*