jedis使用-pool池(2,9版本)

首先建立線程池:
public voidRedisPool() {
if(Const.jedisPoolCommon==null){
JedisPoolConfig config = new JedisPoolConfig();
//最大鏈接數, 默認8個
config.setMaxTotal(redisPoolMaxActive);
//最大空閒鏈接數, 默認8個
config.setMaxIdle(redisPoolMaxIdle);
//獲取鏈接時的最大等待毫秒數
config.setMaxWaitMillis(100000);
//最小空閒鏈接數, 默認0
config.setMinIdle(redisPoolMinIdle);
//鏈接耗盡時是否阻塞, false報異常,ture阻塞直到超時, 默認true
config.setBlockWhenExhausted(true);
config.setTestOnBorrow(TEST_ON_BORROW);
Const.jedisPoolCommon = new JedisPool(config,host,port,timeout,password);
}
}redis

工具使用池:
/**ide

  • 列表添加爲例
  • @param k
  • @param v*/public void rightPush(String k,String v){Jedis jedis = null;try{jedis=Const.jedisPoolCommon.getResource();jedis.select(commdbIndex);jedis.rpush(k,v);}catch (Exception ex){logger.error("rightPush異常"+ex);}finally {if(jedis!=null){//關閉回收到線程池jedis.close();}}}
相關文章
相關標籤/搜索