java – Jedis – 何时使用returnBrokenResource()

前端之家收集整理的这篇文章主要介绍了java – Jedis – 何时使用returnBrokenResource()前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我们应该使用这种方法.在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. Jedis对象表示与Redis的连接.当物理连接断开或客户端与服务器之间的同步丢失时,它将变得不可用.

使用Jedis,这些错误由JedisConnectionException表示.所以我会使用returnBrokenResource这个异常,而不是其他的.

JedisDataException与Jedis API的不良用法或服务器端的Redis错误有关.

JedisException是为了其他一切(通常在较低级别的错误之后提出,独立于Jedis).

原文链接:https://www.f2er.com/java/125371.html

猜你在找的Java相关文章