Wednesday, December 20, 2017

Redis::TimeoutError in Rails application

Leave a Comment

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 

1 Answers

Answers 1

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 Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment