I keep getting Redis::Timeout error in my application (both in UI and in background jobs). I am using AWS ElastiCache service for Redis.
This is how I create a Redis connection. In my config/application.rb , I have:
$redis = Redis.new(host: REDIS_HOST, port: REDIS_PORT, db: REDIS_DB)
How can I avoid getting timeout errors? I am using the default connection settings as follows:
> $redis.client.options[:reconnect_attempts]
=> 1
> $redis.client.options[:timeout]
=> 5.0
> $redis.client.options[:tcp_keepalive]
=> 0
> $redis.client.options[:inherit_socket]
=> false
You should pool your Redis connections with the help of the Connection Pool Gem and increase the timeout value if the problem persists:
ConnectionPool.new(size: 5, timeout: 3) {Redis.new({:host => 'localhost', :port => 6379, :db => 1, :timeout => 240})}
Redis Gem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With