Jedis-何时使用returnBrokenResource() [英] Jedis - When to use returnBrokenResource()

查看:47
本文介绍了Jedis-何时使用returnBrokenResource()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么时候才应该使用此方法.在JedisConnectionException,JedisDataException或任何JedisException上.据我所知,Jedis没有很好的API文档.

When exactly we should use this method. On JedisConnectionException, JedisDataException or for any JedisException. There is no good API documentation for Jedis to my knowledge.

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的连接.当物理连接断开或客户端与服务器之间的同步丢失时,它将变得不可用.

You are supposed to use returnBrokenResource when the state of the object is unrecoverable. A Jedis object represents a connection to Redis. It becomes unusable when the physical connection is broken, or when the synchronization between the client and server is lost.

对于Jedis,这些错误由JedisConnectionException表示.因此,对于该异常,我将使用returnBrokenResource,而不是其他异常.

With Jedis, these errors are represented by the JedisConnectionException. So I would use returnBrokenResource for this exception, and not the other ones.

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

JedisDataException is more related to bad usage of the Jedis API, or to server-side Redis errors.

JedisException适用于所有其他内容(通常在较低级别的错误之后引发,独立于Jedis.)

JedisException is for everything else (usually raised after a lower-level error, independant from Jedis).

这篇关于Jedis-何时使用returnBrokenResource()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆