Skip to content
Back to Deployment

Deploying Redis

Self-hosted Redis with Docker, persistence, sentinel for HA, and cluster for sharding.

PlatformsIntermediate

Why

Self-hosted Redis gives control over persistence (RDB/AOF), memory limits, and modules (RediSearch, RedisJSON). Redis Sentinel provides HA, Cluster provides sharding.

Platform-as-a-Service adoption grew 24% in 2024 as teams shift from VM management to git-push deploys. the cloud infrastructure market reached $330B in 2024, growing 22% year-over-year (Synergy Research), and PaaS layers capture the majority of new workloads.

When

Use self-hosted Redis for custom modules, cost at scale, and specific persistence needs. Prefer Upstash/Redis Cloud for managed.

How

1. Docker — redis:7 image with volume 2. Persistence — AOF (appendonly yes) or RDB snapshots 3. Auth — requirepass in redis.conf 4. Sentinel — 3 sentinels monitor master for HA 5. Cluster — redis-cli --cluster create for sharding 6. Modules — loadmodule for RediSearch, RedisJSON 7. Monitoring — INFO, SLOWLOG, latency monitor

Example

# docker-compose.yml services: redis: image: redis:7 command: redis-server --appendonly yes --requirepass secret volumes: - redisdata:/data ports: ["6379:6379"] volumes: redisdata: # redis.conf appendonly yes appendfsync everysec maxmemory 1gb maxmemory-policy allkeys-lru requirepass your-secret # Sentinel for HA sentinel monitor mymaster redis1 6379 2 sentinel down-after-milliseconds mymaster 5000 # Connect redis-cli -h redis -a secret > SET key value > GET key

Common Problems

  • ⚠No persistence — default is in-memory only, data lost on restart, enable AOF
  • ⚠Memory full — no maxmemory set, Redis uses all RAM then OOM killed
  • ⚠Configuration drift between environments — use infrastructure-as-code (Terraform/Pulumi) to keep dev/staging/prod identical

Best Practices

  • ✓Enable AOF with appendfsync everysec — best durability/performance balance
  • ✓Set maxmemory + eviction policy — prevents OOM, LRU evicts least used
  • ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit

FAQ