This chapter covers the core features and capabilities of Redis Patterns Library.
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.
GETDEL requires 6.2+,and the eviction notes assume the 7.x maxmemory policies. Where a feature
needs a newer server, the doc says so.
redis-cli on your PATH for the shell walkthroughs.examples/ scripts. They use only the standardlibrary — socket, time, hashlib, uuid. There is nothing to install.
127.0.0.1:6379;override with the REDIS_HOST / REDIS_PORT environment variables.
Hostnames such as
cache01.example.comthroughout the docs are placeholders.Replace them with your own. No real infrastructure, addresses, or credentials
appear anywhere in this product.
Follow this guide to get Redis Patterns Library up and running in your environment.
# 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
python3 examples/rate_limiter.py
python3 examples/distributed_lock.pyThe --eval form passes everything before the , as KEYS and everything
after as ARGV. The exact argument order for each script is documented at the
top of the .lua file and in the matching pattern doc.
redis-patterns-library/
├── README.md This file
├── LICENSE MIT
├── config/
│ └── redis.conf Annotated tuning: memory, eviction, persistence, latency
├── docs/
│ ├── caching-strategies.md Cache-aside, read-through, write-through, write-behind, stampede control
│ ├── rate-limiting.md Fixed window, sliding window, token bucket, leaky bucket — trade-offs + Lua
│ ├── distributed-locks.md SET NX PX, fencing tokens, safe release, Redlock caveats
│ ├── pubsub-and-streams.md Pub/sub vs Streams, consumer groups, claiming, dead-letter handling
│ ├── leaderboards-and-sorted-sets.md Ranking, pagination, ties, time-decay, top-N
│ └── ttl-and-eviction.md TTL hygiene, eviction policies, memory accounting, OOM debugging
├── lua/
│ ├── token_bucket.lua Atomic token-bucket rate limiter
│ ├── sliding_window.lua Atomic sliding-window-log rate limiter
│ ├── acquire_lock.lua Atomic lock acquire with monotonic fencing token
│ └── release_lock.lua Owner-checked safe release
├── scripts/
│ ├── cache_aside_demo.sh Cache-aside hit/miss/invalidate walkthrough
│ ├── leaderboard_demo.sh Sorted-set leaderboard: rank, range, pagination
│ └── streams_consumer_group.sh XADD / XREADGROUP / XACK / XAUTOCLAIM end to end
└── examples/
├── redis_client.py Minimal stdlib-only RESP client (socket-level)
├── rate_limiter.py Token-bucket limiter calling the Lua script via EVAL
├── distributed_lock.py Context-manager lock with fencing token + safe release
└── sample_data.redis Seed data for the leaderboard / cache demos
Get the full Redis Patterns Library and unlock everything.
Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.
Access all interactive tools with complete data, all workload profiles, and the full scenario library.
Downloadable source code, configuration files, and working examples from every chapter.
Free updates for life. Every new chapter, tool, and improvement included.