JedisPool的returnResourceObject(Jedis jedis)方法无法调用

最近写的一个项目准备使用redis作缓存,但是在使用JedisPool的时候,我发现returnResourceObject(Jedis jedis)方法无法调用,

经过一番百度之后,发现在jedis2.8.2中

已经将JedisPool#returnResource方法废弃了,

并明确说明这个方法的功能由 Jedis.close() 方法代替

附上代码


    /**
     * 创建 JedisPool连接池
     * @return
     */
    public static JedisPool getJedisPoolInstance() {
        if(jedisPool == null) {
            synchronized (JedisPool.class) {
                if(jedisPool == null) {
                    JedisPoolConfig poolConfig = new JedisPoolConfig();
                    poolConfig.setMaxTotal(maxActive);
                    poolConfig.setMaxIdle(maxIdIe);
                    poolConfig.setMaxWaitMillis(maxWait);
                    poolConfig.setTestOnBorrow(true);

                    jedisPool = new JedisPool(poolConfig,host,port);
                }
            }
        }
        return jedisPool;
    }

    /**
     * 释放连接
     * @param jedis
     */
    public static void release(Jedis jedis) {
        if(null != jedis) {
            jedis.close();
        }
    }

猜你喜欢

转载自blog.csdn.net/zhousw1999/article/details/85345714