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?
The Java CodeJedis jedis = new Jedis("localhost"); // prints out "Connection Successful" if Java successfully connects to Redis server. Here is a breakdown of the above code: Jedis jedis = new Jedis("localhost"); This connects our Java to Redis server running on our local host.
The maximum length of time to wait while establishing a connection to a Redis server.
Continuously opening connections without closing is not a good practice. This will not only consume your resources but may also lead to program crash. The maximum number of file descriptors that you can open simultaneously is 1024.
The latest version of Jedis has support to connect with Redis Cluster.
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
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