`
chenyuguxing
  • 浏览: 38085 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

jedis包括2.4.1,2.5.1等高版本的JedisPoolConfig没有maxActive属性

 
阅读更多
jedis包括2.4.1,2.5.1等高版本的JedisPoolConfig没有maxActive属性,不能按照网上那些方式去配置redis了,网上大部分搜索出来的redis配置都是基于旧版本的jedis,在jedis新版本,JedisPoolConfig没有maxActive属性,JedisPoolConfig没有maxWait属性,以及被替换成其他的命名。
下面是网上的转载,转载之后是jedis高版本JedisPoolConfig没有maxActive,maxWait的解决方法。

使用spring提供的jedis template类感觉操作挺不爽的,至于模板其它优点暂不想去升级,准备直接使用jedis api操作。
下面是网上随处可见的一段代码。
?
1
2
3
4
5
6
7
8
9
10
11
12
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxActive(Integer.valueOf(bundle
.getString("redis.pool.maxActive")));
config.setMaxIdle(Integer.valueOf(bundle
.getString("redis.pool.maxIdle")));
config.setMaxWait(Long.valueOf(bundle.getString("redis.pool.maxWait")));
config.setTestOnBorrow(Boolean.valueOf(bundle
.getString("redis.pool.testOnBorrow")));
config.setTestOnReturn(Boolean.valueOf(bundle
.getString("redis.pool.testOnReturn")));
pool = new JedisPool(config, bundle.getString("redis.ip1"),
Integer.valueOf(bundle.getString("redis.port")));

构造连接池配置文件,但是让我十分蛋疼的就是,setMaxActive提示没这个方法,查看源码JedisPoolConfig继承至GenericObjectPoolConfig,其父类中确实也没有MaxActive这个属性,WHY?难道网上疯传的都是以讹传讹?暂时不去想这个可能性不大的问题,看了下GenericObjectPoolConfig类所在的jar包,org.apache.commons.pool2.impl.GenericObjectPoolConfig,apache提供的xx池,当然平时用的多的是另一个包,我首先就猜测是不是有同名的类文件,Ctrl+T,果然有,继续看,还真存在MaxActive属性,WHY?难道是JedisPoolConfig继承错了,果断自己重载此类,然而JedisPool构造函数有出错,提示必须是org.apache.commons.pool2.impl.GenericObjectPoolConfig的实例,抓狂了叫喊,各种纠结,最后没辙,只能从开源仓库中下载一个个不同版本的jar,找到jedis-2.2.0时,眼前一亮,靠,JedisPoolConfig继承的就是我们熟悉的org.apache.commons.pool.impl.GenericObjectPool.Config。
jedis的大神们做扩展时,能不能考虑下代码的兼容性。。。。

通过这个链接,我们知道commons-pool2 的maxactive,maxWait已经更改命名。
http://mail-archives.apache.org/mod_mbox/tomcat-dev/201403.mbox/<20140305154712.6B9E123889E2@eris.apache.org>
dbcp的修改日志显示:change "maxActive" -> "maxTotal" and "maxWait" -> "maxWaitMillis" in all examples.
所以高版本jedis配置JedisPoolConfig的maxActive,maxWait应该为:
?
1
2
3
4
5
6
7
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.pool.maxIdle}" />
<property name="maxTotal" value="${redis.pool.maxActive}" />
<property name="maxWaitMillis" value="${redis.pool.maxWait}" />
<property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />
<property name="testOnReturn" value="${redis.pool.testOnReturn}" />
</bean>


文摘标签:jedis高版本,JedisPoolConfig,maxActive属性,maxWait,配置maxActive,maxTotal,maxWaitMillis
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics