jedis源码关于连接池思考


jedis以common-pool的GenericObjectPool来管理与redis的连接池

创建JedisPool对象时需传入管理连接池的相关参数,各参数的含义请参考common-pool的相关参数。

config.minIdle=url.getParameter("minIdle", 3);
config.maxIdle=url.getParameter("maxIdle",5);
config.maxActive=url.getParameter("maxActive",10);
config.maxWait=url.getParameter("maxWait",10000);
//----------------------------
config.testOnBorrow=url.getParameter("testOnBorrow", true);
config.testWhileIdle=url.getParameter("testWhileIdle",true);
config.timeBetweenEvictionRunsMillis=url.getParameter("timeBetweenEvictionRunsMillis",120*1000l);
config.testOnReturn=url.getParameter("testOnReturn",false);
//
config.minEvictableIdleTimeMillis=url.getParameter("minEvictableIdleTimeMillis", 300*1000l);
//
config.whenExhaustedAction=(byte)url.getParameter("whenExhaustedAction",1);
config.numTestsPerEvictionRun=url.getParameter("numTestsPerEvictionRun",10);

jedisPool=new JedisPool(config, host, port, timeout,password);

(1)有借有还
(2)用完即还
(3)每还必验
(4)损有余,补不足

你可能感兴趣的:(redis,连接池,jedis)