This document provides instructions for integrating Redis caching into your Evolution API deployment. Redis is NOT required for basic operation and should only be added when needed for performance optimization with larger teams (50+ users).
- When to Use Redis
- Prerequisites
- Installation
- Configuration
- Verification
- Monitoring
- Troubleshooting
- Removal
Consider adding Redis when:
- Team size exceeds 50 users
- Message volume exceeds 2000 messages/day
- Response times are consistently above 200ms
- Database queries are causing bottlenecks
- Multiple instances need session sharing
- ❌ Team has less than 50 users
- ❌ Message volume is under 2000 messages/day
- ❌ Current performance is satisfactory
- ❌ Want to minimize infrastructure complexity
- ❌ Want to reduce resource costs
Important: Evolution API works perfectly without Redis. The default PostgreSQL-only setup is optimized for most use cases (1-50 users).
Before installing Redis:
- Verify current performance is insufficient
- Monitor resource usage to ensure Redis is needed
- Ensure Dokku Redis plugin is available
- Plan for additional resource allocation (Redis needs ~128MB RAM minimum)
Linux/macOS:
dokku plugin:install https://github.com/dokku/dokku-redis.git redisWindows (PowerShell - Remote):
ssh your-server "dokku plugin:install https://github.com/dokku/dokku-redis.git redis"Create Redis service:
dokku redis:create evoExpected Output:
-----> Starting container
Waiting for container to be ready
-----> Creating container database
-----> Redis container created: evo
Link Redis to Evolution API:
dokku redis:link evo evoThis will automatically set the REDIS_URL environment variable.
Verify link:
dokku redis:info evoSet environment variables:
dokku config:set evo CACHE_REDIS_ENABLED=true
dokku config:set evo CACHE_REDIS_URI="$(dokku config:get evo REDIS_URL)"Optional - Set custom prefix:
dokku config:set evo CACHE_REDIS_PREFIX_KEY="evolution"Optimize Redis for your workload:
# For small teams (50-100 users)
dokku redis:set evo maxmemory 128mb
dokku redis:set evo maxmemory-policy allkeys-lru
# For medium teams (100-200 users)
dokku redis:set evo maxmemory 256mb
dokku redis:set evo maxmemory-policy allkeys-lru
# For large teams (200+ users)
dokku redis:set evo maxmemory 512mb
dokku redis:set evo maxmemory-policy allkeys-lruRestart to apply changes:
dokku ps:restart evoConnect to Redis CLI:
dokku redis:connect evoTest Redis commands:
# Inside Redis CLI
PING
# Expected: PONG
INFO stats
# Should show connection info
KEYS evolution:*
# Shows cached keys (if any)
exit
Check Evolution API logs:
dokku logs evo --tail 100Look for Redis connection messages:
[INFO] Redis cache enabled
[INFO] Connected to Redis at redis://...
Before Redis:
# Check response time
curl -w "@curl-format.txt" -o /dev/null -s "https://your-domain.com/health"Create curl-format.txt:
time_total: %{time_total}s\n
After Redis (should show faster response times):
curl -w "@curl-format.txt" -o /dev/null -s "https://your-domain.com/health"Check Redis stats:
dokku redis:info evoView Redis logs:
dokku redis:logs evoMonitor memory usage:
dokku redis:connect evo
# Inside Redis CLI
INFO memoryCheck API response times:
# Create monitoring script
cat > /root/monitor-redis.sh << 'EOF'
#!/bin/bash
echo "=== Redis Stats ==="
dokku redis:info evo | grep -E "used_memory|connected_clients|total_commands"
echo -e "\n=== Evolution API Response Time ==="
curl -w "Response time: %{time_total}s\n" -o /dev/null -s "https://your-domain.com/health"
EOF
chmod +x /root/monitor-redis.shRun monitoring:
/root/monitor-redis.shCreate backup:
dokku redis:backup evo backup-$(date +%Y%m%d-%H%M%S)Schedule automated backups (daily at 2 AM):
# Create backup script
cat > /root/backup-redis.sh << 'EOF'
#!/bin/bash
BACKUP_NAME="redis-backup-$(date +%Y%m%d-%H%M%S)"
dokku redis:backup evo $BACKUP_NAME
dokku redis:backup-list evo | head -n 20
EOF
chmod +x /root/backup-redis.sh
# Add to crontab
echo "0 2 * * * /root/backup-redis.sh" | crontab -List backups:
dokku redis:backup-list evoRestore from backup:
dokku redis:backup-restore evo backup-nameProblem: Application can't connect to Redis
Solution:
# Check Redis is running
dokku redis:info evo
# Verify link
dokku redis:links evo
# Check environment variable
dokku config:get evo REDIS_URL
# Restart services
dokku redis:restart evo
dokku ps:restart evoProblem: Redis consuming too much memory
Solution:
# Check current memory usage
dokku redis:connect evo
# Inside Redis CLI: INFO memory
# Reduce max memory
dokku redis:set evo maxmemory 128mb
# Clear cache if needed
dokku redis:connect evo
# Inside Redis CLI: FLUSHALLProblem: No performance improvement after Redis installation
Possible causes:
- Redis not actually needed (workload too small)
- Incorrect configuration
- Database is the bottleneck, not cache
Solution:
# Profile the application
dokku logs evo --tail 1000 | grep -E "slow|timeout|error"
# Check if Redis is being used
dokku redis:connect evo
# Inside Redis CLI: INFO stats
# Look for "total_commands_processed"
# If Redis shows low usage, consider removing itProblem: Redis connection timeout errors
Solution:
# Increase timeout
dokku config:set evo CACHE_REDIS_CONNECT_TIMEOUT=10000
# Check Redis service health
dokku redis:restart evo
dokku redis:logs evoIf you decide Redis is not needed, you can safely remove it:
dokku config:unset evo CACHE_REDIS_ENABLED
dokku config:unset evo CACHE_REDIS_URI
dokku config:unset evo CACHE_REDIS_PREFIX_KEYdokku ps:restart evoUnlink Redis from application:
dokku redis:unlink evo evoDestroy Redis instance:
dokku redis:destroy evoConfirm deletion when prompted.
If you don't need Redis for any other apps:
dokku plugin:uninstall redisAdvantages:
- ✅ Faster API response times (50-100ms improvement)
- ✅ Reduced database load
- ✅ Better handling of concurrent requests
- ✅ Session data caching
Trade-offs:
- ❌ Additional 128-512MB RAM usage
- ❌ More complex infrastructure
- ❌ Additional monitoring required
- ❌ Higher maintenance overhead
Advantages:
- ✅ Simpler infrastructure
- ✅ Lower resource usage (256MB total)
- ✅ Easier to maintain
- ✅ Lower costs
- ✅ Fewer failure points
Trade-offs:
- ❌ Slightly slower response times (acceptable for small teams)
- ❌ Database does more work (still fine for small workloads)
- Start without Redis - Only add when performance metrics indicate need
- Monitor before and after - Measure actual performance improvement
- Set memory limits - Prevent Redis from consuming too much RAM
- Regular backups - Schedule automated Redis backups
- Monitor cache hit ratio - Ensure Redis is actually being used effectively
- Set expiration policies - Prevent stale data accumulation
- Use appropriate eviction policy -
allkeys-lruis recommended for most cases
Redis is a powerful caching solution that can significantly improve Evolution API performance for larger teams (50+ users). However, it adds complexity and resource overhead that is unnecessary for smaller deployments.
Key Takeaways:
- ✅ Evolution API works perfectly without Redis for teams under 50 users
- ✅ Only add Redis when performance metrics indicate a clear need
- ✅ Monitor performance before and after Redis installation
- ✅ Redis can be safely added or removed at any time
- ✅ Default PostgreSQL-only setup is optimized for most use cases
Next Steps:
- Performance Optimization - Additional optimization techniques
- Configuration Guide - Complete environment variable reference
- Useful Commands - Redis management commands