什么时候我们应该使用这个方法。关于 JedisConnectionException、JedisDataException 或任何 JedisException。据我所知,Jedis 没有好的 API 文档。
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);
}
最佳答案
对于迟到者!
returnBrokenResource()、returnResource() 已弃用。只需在 finally block 中安全地使用 jedis.close()。
finally {
if (jedis != null) {
jedis.close();
}
}
If Jedis was borrowed from pool, it will be returned to pool with proper method since it already determines there was JedisConnectionException occurred. If Jedis wasn't borrowed from pool, it will be disconnected and closed.
关于java - Jedis - 何时使用 returnBrokenResource(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17082163/