Learn Labs
Foundations

Docker & Setup

The minimal and production-shaped stacks, users, and the lab profiles

Like every module in this repo, Redis runs in Docker, with two compose files in redis/.

The minimal stack

services:
redis:
  image: redis:8.8.3
  ports:
    - "6379:6379"
  volumes:
    - redis_data:/data
volumes:
redis_data:
cd redis
docker compose up -d
docker compose exec redis redis-cli

127.0.0.1:6379> PING
PONG
127.0.0.1:6379> SET hello world
OK
127.0.0.1:6379> GET hello
"world"

This runs Redis with its built-in defaults: no password, no memory limit, RDB snapshots only. Fine for the first lessons; unsafe anywhere else.

The production-shaped stack

compose_prod.yaml adds a config file, ACL users, persistence, a memory cap, monitoring, and a GUI:

compose_prod.yaml services
redisthe primary, with config/redis.conf and config/users.acl. :6379redis-exporterPrometheus metrics, scraped by ../prometheus. :9121redisinsightofficial GUI. :5540redis-replica-1/2profile "ha": async replicas of redissentinel-1/2/3profile "ha": automatic failoverredis-node-1..6profile "cluster": a 3-primary, 3-replica Redis Clusterlabsprofile "labs": Python scripts for the pattern lessons
docker compose down        # stop the minimal one first; both publish 6379
cp .env.example .env
docker compose -f compose_prod.yaml up -d
docker exec -it redis redis-cli --user default --pass redis123

The config file

config/redis.conf sets everything explicitly. The settings that matter most:

aclfile /usr/local/etc/redis/users.aclusers and permissionsmaxmemory 256mbcap the datasetmaxmemory-policy volatile-lfuevict least-frequently-used keys that have a TTLappendonly yeslog every write (AOF)appendfsync everysecfsync once a second: lose at most ~1s on crashsave 3600 1 300 100 60 10000RDB snapshots tooslowlog-log-slower-than 10000record commands slower than 10msmasteruser default / masterauth ...credentials used when this node is a replica

Each one gets its own lesson later. Check any running value with CONFIG GET maxmemory*.

Users

config/users.acl defines four users. Redis checks every command against the connected user's permissions:

UserPasswordAllowed
defaultredis123Everything
appapp123Normal commands on app:*, cache:*, session:*, rate:*, lock:*, lb:*, stream:* only; no admin or dangerous commands
readonlyreadonly123Read commands on all keys
exporterexporter123The handful of commands redis_exporter needs
docker exec -it redis redis-cli --user app --pass app123
127.0.0.1:6379> SET app:greeting hi
OK
127.0.0.1:6379> SET other:key hi
(error) NOPERM No permissions to access a key
127.0.0.1:6379> FLUSHALL
(error) NOPERM User app has no permissions to run the 'flushall' command

Applications should always connect as a restricted user like app. More in Security.

The lab profiles

# Python labs (build once)
docker compose -f compose_prod.yaml --profile labs build labs
docker compose -f compose_prod.yaml run --rm labs python seed.py

# replication + Sentinel failover
docker compose -f compose_prod.yaml --profile ha up -d

# Redis Cluster
docker compose -f compose_prod.yaml --profile cluster up -d

RedisInsight

Open http://localhost:5540, choose Add Redis database, and enter host redis, port 6379, username default, password redis123. (The host is redis, not localhost, because RedisInsight connects from inside the Docker network.) It shows every key with its type, TTL, and memory, plus a slowlog viewer and a profiler. Useful for exploring; the lessons use redis-cli so you learn the commands themselves.

Monitoring

The Prometheus stack from the Prometheus & Grafana module already scrapes redis-exporter (job redis), has Redis alerts, and provisions a Redis Overview dashboard. Start it from ../prometheus whenever you want graphs while working through these lessons.

Everyday commands

# shell
docker exec -it redis redis-cli --user default --pass redis123

# one-off commands
docker exec redis redis-cli --user default --pass redis123 --no-auth-warning INFO memory

# stop, keep data
docker compose -f compose_prod.yaml stop

# remove everything, including data
docker compose -f compose_prod.yaml --profile ha --profile cluster down -v

On this page