This runbook covers troubleshooting procedures for Redis cache issues in the Poultry Platform.
Cache Provider: Redis 7.x Deployment: Kubernetes StatefulSet / Docker Compose Client: Spring Data Redis (Lettuce)
- Quick Diagnostics
- Connection Issues
- Performance Issues
- Memory Issues
- Data Issues
- Cluster Issues
- Recovery Procedures
# Kubernetes: Check Redis pod status
kubectl get pods -n poultry-platform -l app=redis
# Kubernetes: Check Redis logs
kubectl logs -f redis-0 -n poultry-platform --tail=50
# Docker: Check Redis container
docker compose ps redis
docker compose logs -f redis --tail=50
# Application health check
curl -s https://api.poultry-platform.com/api/actuator/health | jq '.components.redis'# Connect to Redis
kubectl exec -it redis-0 -n poultry-platform -- redis-cli
# Basic health check
redis-cli PING
# Expected: PONG
# Server info
redis-cli INFO server
# Memory info
redis-cli INFO memory
# Connected clients
redis-cli INFO clients
# Check key count
redis-cli DBSIZE# Get all stats
kubectl exec -it redis-0 -n poultry-platform -- redis-cli INFO
# Key metrics to check:
# - connected_clients: Number of client connections
# - used_memory: Memory in use
# - used_memory_peak: Peak memory usage
# - evicted_keys: Keys evicted due to maxmemory
# - keyspace_hits/misses: Cache hit ratio
# - rejected_connections: Connections rejectedSymptoms:
- Application logs show "Connection refused"
- Health check shows Redis as DOWN
Diagnosis:
# Check if Redis is running
kubectl get pods -n poultry-platform -l app=redis
kubectl describe pod redis-0 -n poultry-platform
# Check Redis logs
kubectl logs redis-0 -n poultry-platform --tail=100
# Test connectivity from application pod
kubectl exec -it deployment/poultry-backend -n poultry-platform -- \
nc -zv redis 6379
# Test Redis ping
kubectl exec -it deployment/poultry-backend -n poultry-platform -- \
redis-cli -h redis pingResolution:
-
If pod not running, check events and restart:
kubectl get events -n poultry-platform | grep redis kubectl rollout restart statefulset/redis -n poultry-platform -
Check resource limits:
kubectl describe pod redis-0 -n poultry-platform | grep -A 5 "Limits:\|Requests:"
-
Verify service configuration:
kubectl get svc redis -n poultry-platform kubectl describe svc redis -n poultry-platform
Symptoms:
- Intermittent timeouts
- Slow Redis operations
Diagnosis:
# Check client connections
kubectl exec -it redis-0 -n poultry-platform -- redis-cli CLIENT LIST
# Check slow log
kubectl exec -it redis-0 -n poultry-platform -- redis-cli SLOWLOG GET 10
# Check network latency
kubectl exec -it deployment/poultry-backend -n poultry-platform -- \
redis-cli -h redis --latency
# Check for connection exhaustion
kubectl exec -it redis-0 -n poultry-platform -- redis-cli INFO clientsResolution:
-
Increase connection timeout in application:
spring: data: redis: timeout: 5000ms # Increase from default
-
Tune TCP keepalive:
redis-cli CONFIG SET tcp-keepalive 60
-
Increase maxclients if needed:
redis-cli CONFIG SET maxclients 20000
Symptoms:
- "NOAUTH Authentication required"
- "ERR invalid password"
Diagnosis:
# Check if password is configured
kubectl get secret redis-credentials -n poultry-platform -o jsonpath='{.data.password}' | base64 -d
# Test authentication
kubectl exec -it redis-0 -n poultry-platform -- redis-cli AUTH <password>Resolution:
- Verify password in application configuration
- Update secret if password changed:
kubectl create secret generic redis-credentials \ --from-literal=password=<new-password> \ --dry-run=client -o yaml | kubectl apply -f -
- Restart application to pick up new credentials
Symptoms:
- Redis operations taking > 10ms
- Application slowdowns
Diagnosis:
# Check slow log
kubectl exec -it redis-0 -n poultry-platform -- redis-cli SLOWLOG GET 25
# Check latency
kubectl exec -it redis-0 -n poultry-platform -- redis-cli --latency
# Check if persistence is causing issues
kubectl exec -it redis-0 -n poultry-platform -- redis-cli INFO persistence
# Check big keys
kubectl exec -it redis-0 -n poultry-platform -- redis-cli --bigkeysResolution:
-
Identify and optimize slow operations from SLOWLOG
-
Disable persistence if not needed:
redis-cli CONFIG SET save "" redis-cli CONFIG SET appendonly no -
Enable lazy freeing:
redis-cli CONFIG SET lazyfree-lazy-eviction yes redis-cli CONFIG SET lazyfree-lazy-expire yes
-
Consider pipelining for batch operations
Symptoms:
- Cache hit ratio < 80%
- Increased database load
Diagnosis:
# Check hit ratio
kubectl exec -it redis-0 -n poultry-platform -- redis-cli INFO stats | grep keyspace
# Calculate hit ratio
# hits / (hits + misses) * 100
# Check TTL distribution
kubectl exec -it redis-0 -n poultry-platform -- redis-cli DEBUG OBJECT <key>Resolution:
- Review cache TTL settings - may be too short
- Ensure cache warming on application startup
- Check if keys are being evicted prematurely
- Review caching strategy in application
Symptoms:
- Single keys accessed very frequently
- Uneven load distribution (in cluster)
Diagnosis:
# Monitor key access patterns
kubectl exec -it redis-0 -n poultry-platform -- redis-cli MONITOR | head -1000
# Check client output buffer
kubectl exec -it redis-0 -n poultry-platform -- redis-cli INFO clientsResolution:
- Implement local caching (L1 cache) for hot keys
- Use read replicas for hot keys
- Consider key sharding (key:1, key:2, etc.)
Symptoms:
- Redis using > 80% of allocated memory
- OOM killer risk
- Keys being evicted
Diagnosis:
# Check memory usage
kubectl exec -it redis-0 -n poultry-platform -- redis-cli INFO memory
# Check eviction stats
kubectl exec -it redis-0 -n poultry-platform -- redis-cli INFO stats | grep evicted
# Find big keys
kubectl exec -it redis-0 -n poultry-platform -- redis-cli --bigkeys
# Memory analysis
kubectl exec -it redis-0 -n poultry-platform -- redis-cli MEMORY DOCTORResolution:
-
Immediate: Increase maxmemory:
redis-cli CONFIG SET maxmemory 2gb
-
Clean up: Delete unnecessary keys:
# Find and delete expired session keys redis-cli KEYS "session:*" | xargs redis-cli DEL
-
Optimize data structures:
- Use hashes instead of strings for related data
- Use appropriate encoding (ziplist, intset)
-
Configure eviction policy:
redis-cli CONFIG SET maxmemory-policy allkeys-lru
Symptoms:
mem_fragmentation_ratio> 1.5- High memory usage despite low key count
Diagnosis:
# Check fragmentation ratio
kubectl exec -it redis-0 -n poultry-platform -- redis-cli INFO memory | grep fragmentation
# mem_fragmentation_ratio > 1.5 indicates fragmentationResolution:
-
Enable active defragmentation:
redis-cli CONFIG SET activedefrag yes redis-cli CONFIG SET active-defrag-ignore-bytes 100mb redis-cli CONFIG SET active-defrag-threshold-lower 10
-
If severe, restart Redis during low-traffic period
Symptoms:
- "OOM command not allowed"
- Redis refusing writes
Diagnosis:
# Check memory state
kubectl exec -it redis-0 -n poultry-platform -- redis-cli INFO memory
# Check if maxmemory is set
kubectl exec -it redis-0 -n poultry-platform -- redis-cli CONFIG GET maxmemoryResolution:
-
Emergency: Flush least important data:
# Be very careful with FLUSHDB/FLUSHALL redis-cli SELECT 1 # Non-critical database redis-cli FLUSHDB ASYNC
-
Delete specific key patterns:
redis-cli KEYS "temp:*" | xargs redis-cli DEL
-
Increase maxmemory and pod limits
-
Review and reduce TTLs
Symptoms:
- Outdated data being served
- Inconsistency between database and cache
Diagnosis:
# Check key TTL
kubectl exec -it redis-0 -n poultry-platform -- redis-cli TTL <key>
# Check key last modified
kubectl exec -it redis-0 -n poultry-platform -- redis-cli OBJECT IDLETIME <key>Resolution:
-
Manual invalidation:
# Delete specific key redis-cli DEL <key> # Delete pattern redis-cli KEYS "product:*" | xargs redis-cli DEL
-
Application-level fix:
- Implement cache-aside pattern correctly
- Use write-through caching
- Reduce TTL for frequently updated data
Common Key Patterns in Poultry Platform:
| Pattern | Description | TTL |
|---|---|---|
session:<id> |
User sessions | 24h |
otp:<phone> |
OTP codes | 5m |
product:<id> |
Product cache | 1h |
seller:<id> |
Seller profile | 30m |
rate_limit:<ip> |
Rate limiting | 1m |
# Clear all sessions
redis-cli KEYS "session:*" | xargs -r redis-cli DEL
# Clear all product cache
redis-cli KEYS "product:*" | xargs -r redis-cli DEL
# Clear rate limiting data
redis-cli KEYS "rate_limit:*" | xargs -r redis-cli DELDiagnosis:
# Check cluster info
redis-cli CLUSTER INFO
# Check cluster nodes
redis-cli CLUSTER NODES
# Check for failed nodes
redis-cli CLUSTER NODES | grep failResolution:
- If node is down, check and restart
- If slots are unassigned:
redis-cli CLUSTER ADDSLOTS {slot-number} - Reshard if needed:
redis-cli --cluster reshard <host>:<port>
# Manual failover (on replica)
redis-cli CLUSTER FAILOVER
# Force failover (if master is down)
redis-cli CLUSTER FAILOVER FORCE# Kubernetes
kubectl rollout restart statefulset/redis -n poultry-platform
# Docker Compose
docker compose restart redis
# Wait and verify
kubectl wait --for=condition=ready pod/redis-0 -n poultry-platform --timeout=60s# If using RDB
# 1. Stop Redis
# 2. Replace dump.rdb with backup
# 3. Start Redis
# If using AOF
# 1. Stop Redis
# 2. Replace appendonly.aof with backup
# 3. Run redis-check-aof --fix appendonly.aof
# 4. Start RedisWARNING: This will clear all cached data
# Flush current database only
kubectl exec -it redis-0 -n poultry-platform -- redis-cli FLUSHDB ASYNC
# Flush all databases (use with extreme caution)
kubectl exec -it redis-0 -n poultry-platform -- redis-cli FLUSHALL ASYNC# The application should warm cache on startup
# Monitor cache hit ratio after restart
watch -n 5 'kubectl exec redis-0 -n poultry-platform -- redis-cli INFO stats | grep keyspace'
# If manual warming needed, trigger cache population endpoints
curl -X POST https://api.poultry-platform.com/api/admin/cache/warm# Monitor all commands (use briefly, very verbose)
kubectl exec -it redis-0 -n poultry-platform -- redis-cli MONITOR
# Check latency
kubectl exec -it redis-0 -n poultry-platform -- redis-cli --latency-history
# Check intrinsic latency
kubectl exec -it redis-0 -n poultry-platform -- redis-cli --intrinsic-latency 5# Get all stats
kubectl exec -it redis-0 -n poultry-platform -- redis-cli INFO
# Specific sections
redis-cli INFO server
redis-cli INFO clients
redis-cli INFO memory
redis-cli INFO persistence
redis-cli INFO stats
redis-cli INFO replication
redis-cli INFO cpu
redis-cli INFO cluster
redis-cli INFO keyspace# Memory
maxmemory 1gb
maxmemory-policy allkeys-lru
# Persistence (if enabled)
save 900 1
save 300 10
save 60 10000
# Networking
timeout 0
tcp-keepalive 300
maxclients 10000
# Performance
lazyfree-lazy-eviction yes
lazyfree-lazy-expire yes
lazyfree-lazy-server-del yesspring:
data:
redis:
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD:}
timeout: 2000ms
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 2
max-wait: -1msIf unable to resolve:
- Check Redis documentation
- Escalate to infrastructure team
- Consider Redis support (if using managed service)