12

I have an application that stores and reads date in Redis. When Redis goes down and then comes back up, the Jedis connection is not being recreated.

Is there is a way to create a connection retry in Jedis?

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
Vigneshwaran
  • 782
  • 2
  • 7
  • 22

2 Answers2

5

One way to overcome the issue is to use a connection pool. I'm using JedisPool. While I cannot find anywhere in the documentation that JedisPool supports automatic reconnect, in my tests, I'm able to continue to use Redis cache after service restarted.

Another option is to use lettuce client which claims to support auto-reconnect.

Mikhail Chibel
  • 1,865
  • 1
  • 22
  • 34
3

You may use JedisPool. In case of broken connection JedisPool just invalidates broken connections.

Also you could use Redisson Redis Java client which has internal ConnectionWatchDog to avoid broken connections. Redisson exposes few settings to control Redis command retry logic: retryAttempts, retryInterval, timeout

Nikita Koksharov
  • 10,283
  • 1
  • 62
  • 71