加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Jedis – 何时使用returnBrokenResource()

发布时间:2020-12-14 16:26:20 所属栏目:Java 来源:网络整理
导读:当我们应该使用这种方法.在JedisConnectionException,JedisDataException或任何JedisException.对于Jedis来说,我的知识没有很好的API文档. try { Jedis jedis = JedisFactory.getInstance(); Pipeline pipe = jedis.pipelined(); ResponseSetTuple idWithSco
当我们应该使用这种方法.在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).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读