【撸码师的备忘录】JedisPool.returnResource()遭弃用

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

自Jedis3.0版本后jedisPool.returnResource()遭弃用,官方重写了Jedis的close方法用以代替;

代码如下:

/**
   * @deprecated starting from Jedis 3.0 this method will not be exposed.
   * Resource cleanup should be done using @see {@link redis.clients.jedis.Jedis#close()}
   */
  @Override
  @Deprecated
  public void returnResource(final Jedis resource) {
    if (resource != null) {
      try {
        resource.resetState();
        returnResourceObject(resource);
      } catch (Exception e) {
        returnBrokenResource(resource);
        throw new JedisException("Could not return the resource to the pool", e);
      }
    }
  }



官方建议应用redis.clients.jedis#Jedis的close方法进行资源回收,官方代码如下:

@Override
  public void close() {
    if (dataSource != null) {
      if (client.isBroken()) {
        this.dataSource.returnBrokenResource(this);
      } else {
        this.dataSource.returnResource(this);
      }
    } else {
      client.close();
    }
  }



Note


转载于:https://my.oschina.net/xiehongfei/blog/646125

你可能感兴趣的:(【撸码师的备忘录】JedisPool.returnResource()遭弃用)