Jedis connection retry

1,338 views
Skip to first unread message

Atta Beit

unread,
Mar 26, 2020, 11:10:54 AM3/26/20
to Jedis
I am trying to write reconnect logic when my application loses connection to redis when Redis fails over. Does Jedis provide hooks to retry connection?

Sazzadul

unread,
Jun 2, 2020, 1:31:34 AM6/2/20
to Jedis
No.

Matt Freake

unread,
Jun 2, 2020, 1:44:58 AM6/2/20
to jedis...@googlegroups.com
This does sound similar to the functionality available via JedisPool though. Create a pool of 1 and whenever you return the connection to the pool, its health is checked and a new one created and it is replaced if its not ok.

--
You received this message because you are subscribed to the Google Groups "Jedis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jedis_redis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jedis_redis/2939b2cf-b24e-4a68-a868-a1b29e3dafa2%40googlegroups.com.

Tugdual Grall

unread,
Jun 2, 2020, 10:47:26 AM6/2/20
to Jedis
Hello,

JedisConnectionPool will reconnect/refresh the connection, but the application code must retry.

So your application code should:
* get the connection from the pool
* do the operations
  * in case of exception (connection lost,fail-over), 
        * catch the exception, 
        * implement the retry policy (for example)
        * get a new connection from the pool and retry 


You can find a very basic logic here:

If you are using Spring you can probably implement something with the Spring Retry library. (I have not tested it myself yet)


PS: as you can see in the link below, the fact that Jedis does not provide automatic reconnect/retry is done on purpose to keep the lin as simple as possible:

Regards
Tug
@tgrall
        

On Tuesday, June 2, 2020 at 7:44:58 AM UTC+2, Matt Freake wrote:
This does sound similar to the functionality available via JedisPool though. Create a pool of 1 and whenever you return the connection to the pool, its health is checked and a new one created and it is replaced if its not ok.

On Tue, Jun 2, 2020 at 6:31 AM Sazzadul <sazzad...@gmail.com> wrote:
No.

On Thursday, March 26, 2020 at 9:10:54 PM UTC+6, Atta Beit wrote:
I am trying to write reconnect logic when my application loses connection to redis when Redis fails over. Does Jedis provide hooks to retry connection?

--
You received this message because you are subscribed to the Google Groups "Jedis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jedis...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages