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).

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。