version: '3.8' # Shared Redis Cache # Purpose: Centralized cache and session store for all homelab applications # Port: 6379 # GPU: No # Storage: SSD (Redis persistence - AOF and RDB) services: redis-shared: image: redis:alpine container_name: redis-shared restart: unless-stopped command: > redis-server --appendonly yes --appendfsync everysec --maxmemory 512mb --maxmemory-policy allkeys-lru --save 60 1000 --save 300 100 --save 900 1 --loglevel warning healthcheck: test: ["CMD-SHELL", "redis-cli ping | grep PONG"] start_period: 20s interval: 30s retries: 5 timeout: 3s ports: - "6379:6379" volumes: - /home/jpmschweitzer/docker-data/redis-shared/data:/data environment: TZ: Europe/Amsterdam deploy: resources: limits: cpus: '0.5' memory: 512M reservations: memory: 128M networks: - docker-dataplane networks: docker-dataplane: external: true name: docker-dataplane # Setup Instructions: # # 1. Create directories: # mkdir -p ~/docker-data/redis-shared/data # # 2. Deploy stack: # docker-compose -f redis-shared.yml up -d # # 3. Verify deployment: # docker exec redis-shared redis-cli ping # # Database Allocation: # # Redis supports 16 databases (0-15). Assign one per application: # # DB 0: Authentik (sessions, cache, message queue) # DB 1: Tatlock (memory) # DB 2: Wiki.js # DB 3: Scheduler # DB 4: Library Desk # DB 5: SearXNG # DB 6: Tatlock (benchmarks) # DB 7: Nextcloud (file locking, distributed cache, sessions) # DB 8: Paperless (task queue, cache) # DB 9-15: Reserved for future applications # # Connection Examples: # # From containers on docker-dataplane network: # redis://redis-shared:6379/1 (Authentik, DB 1) # redis://redis-shared:6379/2 (Gitea, DB 2) # # From host machine: # redis-cli -h localhost # SELECT 1 (switch to database 1) # # Monitoring: # # General info: # docker exec redis-shared redis-cli INFO # # Memory usage: # docker exec redis-shared redis-cli INFO memory # # Keyspace (keys per database): # docker exec redis-shared redis-cli INFO keyspace # # Stats: # docker exec redis-shared redis-cli INFO stats # # Per-database keys: # docker exec redis-shared redis-cli -n 1 DBSIZE (database 1) # docker exec redis-shared redis-cli -n 2 DBSIZE (database 2) # # Backup: # # Trigger background save: # docker exec redis-shared redis-cli BGSAVE # # Copy RDB file: # cp ~/docker-data/redis-shared/data/dump.rdb \ # ~/backups/redis-$(date +%Y%m%d).rdb # # Backup AOF (append-only file): # cp ~/docker-data/redis-shared/data/appendonly.aof \ # ~/backups/redis-aof-$(date +%Y%m%d).aof # # Restore: # docker stop redis-shared # cp backup-dump.rdb ~/docker-data/redis-shared/data/dump.rdb # docker start redis-shared # # Maintenance: # # Clear specific database (DANGER - data loss!): # docker exec redis-shared redis-cli -n 1 FLUSHDB # # Clear all databases (DANGER - total data loss!): # docker exec redis-shared redis-cli FLUSHALL # # Rewrite AOF (compact log file): # docker exec redis-shared redis-cli BGREWRITEAOF # # Configuration Details: # # Persistence strategy (dual): # - AOF (Append Only File): Real-time durability, fsync every second # - RDB Snapshots: Periodic snapshots (every 60s if 1000+ keys changed) # # Memory policy: # - Max memory: 512MB # - Eviction: allkeys-lru (Least Recently Used eviction when full) # # Resource Usage (expected): # CPU: ~0.1-0.3 cores (low CPU, very efficient) # RAM: ~100-400MB (depends on data, capped at 512MB) # Storage: ~50-200MB (AOF + RDB files) # # Applications Using This Cache: # - Authentik (sessions, policies, background tasks) # - Gitea (sessions, cache, queues) - if migrated # - Nextcloud (file locking, distributed cache, sessions) # - Future applications as needed # # Performance Tips: # - Use pipeline commands for bulk operations # - Set appropriate TTL (Time To Live) on cached keys # - Monitor memory usage to prevent eviction storms # - Use database numbers to isolate application data