Properly handle broken resource #3182
-
Currently from what I see one of the best ways to handle broken resources is mainly the testOnBorrow, which basically would execute a ping before returning the resource, but that can be a + on the latency of the call, even tho small, could be avoided? I'm mainly trying to find the best ways to make sure that the operations would still execute even if it encounters a broken Jedis connection, so far came up with something like: public void executeProcess(Consumer<Jedis> consumer){
Jedis jedis = this.pool.getResource();
try {
consumer.accept(jedis);
} finally {
this.pool.returnResource(jedis);
return;
} catch(Exception exception){
this.pool.returnBrokenResource(jedis);
executeProcess(consumer);
return;
}
} Also including a pubsub safety in case the redis server is restarted, all pubsubs would basicaly disconnect, and if the software does not handle it properly it would basically break, does this seems tangeable or something good? Thread thread = new Thread(()->{
while(true){
// register pubsub here, if the subscription throws an exception, try to subscribe again?
}
});
thread.setDaemon(true);
thread.start(); Any ideas on hw to improve or how to properly handle the fails and still make sure the op executes? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 12 replies
-
For the first part: Try UnifiedJedis with RetryableCommandExecutor.
For the second part: Yes, subscribe is not a strength of this library. We welcome any contribution 🙂 |
Beta Was this translation helpful? Give feedback.
For the first part:
Try UnifiedJedis with RetryableCommandExecutor.
For the second part:
Yes, subscribe is not a strength of this library. We welcome any contribution 🙂