java – Jedis – 何时使用returnBrokenResource()
发布时间:2020-08-16 05:46:06  所属栏目:Java  来源:互联网 
            导读:当我们应该使用这种方法.在JedisConnectionException,JedisDataException或任何JedisException.对于Jedis来说,我的知识没有很好的API文档. try { Jedis jedis = JedisFactory.getInstance(); Pipeline pipe = jedis.pipelined(); Respo
                
                
                
            | 
                         当我们应该使用这种方法.在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). (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
推荐文章
            站长推荐
            - java – Spring MVC测试结果415错误
 - java – 使用Maven,OSGi和Bndtools
 - java – JTable.clearSelection()vs Jtable.getS
 - Java基于正则表达式获取指定HTML标签指定属性值的
 - Java mysql数据库并进行内容查询实例代码
 - java – Spring @ContextConfiguration
 - .net – F#int.MaxValue是“不是有效的常量表达式
 - jsf – 使用javax.faces.PROJECT_STAGE
 - java 基础知识之网络通信(TCP通信、UDP通信、多
 - 在Swing中处理JFXPanel时,JavaFX IllegalStateEx
 
热点阅读
            