Replies: 2 comments
-
I think the 'ping' is suggested for the flow: new Jedis > ping > subscribe, as the subscribe indeed sets an infinite timeout which will happily make it wait forever when you e.g. put in the wrong IP address. Using it to reconnect in case upon connection failure is a bit different I guess, you would have to periodically ping in a separate thread and then take some action when a ping fails. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your response @Venorcis ! You're right, subscribe does the change the timeout to infinity so I should probably PING before subscribing to the pub/sub channel as a sanity. Given that an instance of the Jedis client itself is not thread safe (from what I've come across), I can't reuse that to ping periodically in a separate thread to ensure that the pub/sub connection is active. I don't have control over the TCP keepalive value unfortunately, and I'm not sure about the default value since this is running on a managed platform. I've read that on Linux it can be 2 hours by default, which is rather long for my use case. It doesn't seem like I can use Jedis pub/sub to account for this? IE ensuring that the pub/sub connection remains active while the subscriber thread is blocked? |
Beta Was this translation helpful? Give feedback.
-
Hi folks,
We've been using Jedis at our company for communicating with Redis, and we are currently looking into setting up pub/sub for a certain feature. As part of this, I just wanted to clarify the usage of Jedis wrt pub/sub.
I understand that the call to
subscribe()
on the Jedis client is blocking, but to account for networking issues it is suggested to ping, which is an available method in theJedisPubSub
class. Are there any recommendations on how to use this to detect networking issues so I can attempt to reconnect on failures?Apologies if this is already answered elsewhere, but I haven't seem to have found anything in my searches.
Redis / Jedis Configuration
Jedis version: 3.2.0
Redis version: 4.0.0
Java version: 1.8.0
Beta Was this translation helpful? Give feedback.
All reactions