首先创建线程池:
公共voidRedisPool () {
如果(Const.jedisPoolCommon==null) {
JedisPoolConfig配置=new JedisPoolConfig ();
//最大连接数,默认8个
config.setMaxTotal (redisPoolMaxActive);
//最大空闲连接数,默认8个
config.setMaxIdle (redisPoolMaxIdle);
//获取连接时的最大等待毫秒数
config.setMaxWaitMillis (100000)。
//最小空闲连接数,默认0
config.setMinIdle (redisPoolMinIdle);
//连接耗尽时是否阻塞,假报异常,真正的阻塞直到超时,默认真
config.setBlockWhenExhausted(真正);
config.setTestOnBorrow (TEST_ON_BORROW);
Const。jedisPoolCommon=new JedisPool(配置、主机、端口、超时、密码);
}
}
工具使用池:
/* *
-
<李>列表添加为例李>
<李> @param k 李>
<李> @param v
*/
公共空间rightPush (k字符串,字符串v) {
能能=零;
尝试{
能=Const.jedisPoolCommon.getResource ();
jedis.select (commdbIndex);
jedis.rpush (k、v);
}捕捉(例外的前女友){
logger.error (“rightPush异常“+交货),
}最后{
如果(能!=null){//关闭回收到线程池
jedis.close ();
}
}
} 李>