Contents

Chapter 1

Who this is for

This chapter covers the core features and capabilities of Redis Patterns Library.

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+, 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.
  • 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.

Chapter 2

How to run

Follow this guide to get Redis Patterns Library up and running in your environment.

How to run

bash
# 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.py

The --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.

Contents

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
Chapter 3
🔒 Available in full product

File-by-file guide

Chapter 4
🔒 Available in full product

License

You’ve reached the end of the free preview

Get the full Redis Patterns Library and unlock everything.

All Chapters

Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.

Full Tool Suite

Access all interactive tools with complete data, all workload profiles, and the full scenario library.

Source Files

Downloadable source code, configuration files, and working examples from every chapter.

Lifetime Updates

Free updates for life. Every new chapter, tool, and improvement included.

Buy Now — $29 →
📦 Free sample included — download another copy for the full product.
Redis Patterns Library v1.0.0 — Free Preview