Back to Blog
Redis in Production: Configuration and Best Practices
Redis Powers Laravel
Redis handles caching, sessions, queues, and real-time features in Laravel applications. Proper production configuration ensures reliability and performance.
Memory Configuration
# /etc/redis/redis.conf
# Set max memory (leave room for OS)
maxmemory 2gb
# Eviction policy
maxmemory-policy allkeys-lru
# Persistence
appendonly yes
appendfsync everysec
Laravel Redis Configuration
// config/database.php
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'cache' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', 6379),
'database' => 1,
],
'queue' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', 6379),
'database' => 2,
],
],
Security
# redis.conf
# Bind to localhost only
bind 127.0.0.1
# Require password
requirepass your_strong_password_here
# Disable dangerous commands
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command DEBUG ""
Monitoring
# Check memory usage
redis-cli INFO memory
# Monitor commands in real-time
redis-cli MONITOR
# Slow log
redis-cli SLOWLOG GET 10
High Availability
# Redis Sentinel for automatic failover
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
Conclusion
Redis in production requires proper memory management, security configuration, monitoring, and ideally high availability setup. Configure thoughtfully and monitor continuously.
Related Articles
Need Help With Your Project?
I respond to all inquiries within 24 hours. Let's discuss how I can help build your production-ready system.
Get In Touch