Java – jedis – when to use returnbrokenresource()
•
Java
When we should use this method In jedisconnectionexception, jedisdataexception or any jedisexception For jedis, my knowledge doesn't have a good API document
try { Jedis jedis = JedisFactory.getInstance(); Pipeline pipe = jedis.pipelined(); Response<Set<Tuple>> idWithscore = pipe.zrangeWithscores(cachekey,from,to); **// some statement which may cause some other exception** Response<String> val = pipe.get(somekey); pipe.exec(); pipe.sync(); }catch (JedisConnectionException e) { JedisFactory.returnBrokenResource(jedis); }catch(Exception e){ **// What API I should use here?,how to find whether to use returnBrokenResource(jedis) or returnResource(jedis)** }finally{ JedisFactory.returnResource(jedis); }
Solution
Returnbrokenresource should be used when the state of an object is not recoverable The jedis object represents the connection with redis It becomes unavailable when the physical connection is disconnected or the synchronization between the client and the server is lost
Using jedis, these errors are represented by jedisconnectionexception So I will use the exception returnbrokenresource instead of others
Jedisdataexception is related to bad usage of jedis API or redis error on server side
Jedisexception is for everything else (usually after lower level errors, independent of jedis)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码