配置Jedis连接池时,JedisPoolConfig中没有SetMaxTotal(),setMaxIdle()等方法

初次接触redis数据库,并使用Jedis连接池连接redis数据库

起初使用的jar包为jedis-2.4.2.jar和commons-pool-1.6.jar



import org.junit.Test;


import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class Demo2 {
/**
* 连接池
*/
@Test
public void run1() {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(50);//此处报错
config.setMaxIdle(10);//此处报错
JedisPool pool = new JedisPool(config, "192.168.149.128", 6379);//此处报错
Jedis jedis = pool.getResource();
System.out.println(jedis.get("name"));
jedis.close();
}
}

调查发现JedisPoolConfig.class内容(反编译)如下:

/*jadclipse*/// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.


package redis.clients.jedis;


import org.apache.commons.pool2.impl.GenericObjectPoolConfig;


public class JedisPoolConfig extends GenericObjectPoolConfig
{


    public JedisPoolConfig()
    {
        setTestWhileIdle(true);
        setMinEvictableIdleTimeMillis(60000L);
        setTimeBetweenEvictionRunsMillis(30000L);
        setNumTestsPerEvictionRun(-1);
    }
}




/*
DECOMPILATION REPORT


Decompiled from: D:\android\project_1\Jedis_Project\WebContent\WEB-INF\lib\jedis-2.4.2.jar
Total time: 84 ms
Jad reported messages/errors:
The class file version is 50.0 (only 45.3, 46.0 and 47.0 are supported)
Exit status: 0
Caught exceptions:
*/

原来JedisPoolConfig的父类是org.apache.commons.pool2.impl下面的GenericObjectPoolConfig类,而本次导入的

commons-pool为pool1的,非pool2的,故项目中没有找到其SetMaxTotal(),setMaxIdle()等方法,

进而决定重新导入pool2的jar包,这次导入的commons-pool.jar的版本为2-3.3(commons-pool2-2.3.jar),jedis包依旧为jedis-2.4.2.jar

这样设定后,项目没有报错,正常测试



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CHENG1006748202

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值