首页 > 其他 > 详细

RedisPoolFactory

时间:2019-09-22 15:39:32      阅读:86      评论:0      收藏:0      [点我收藏+]
public class RedisPoolFactory {
private static HashMap<String, JedisPool> poolFactory = new HashMap<String, JedisPool>();

public static JedisPool getPool(String hostname, int port) {
String key = hostname + port;
if (!poolFactory.containsKey(key)) {
synchronized (RedisPoolFactory.class) {
if (!poolFactory.containsKey(key)) {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
//资源池中最大连接数
jedisPoolConfig.setMaxTotal(200);
//资源池允许最大空闲的连接数
jedisPoolConfig.setMaxIdle(30);
//默认值是-1 表示永不超时 不建议使用
jedisPoolConfig.setMaxWaitMillis(10000);
//返回连接时,是否提前进行 validate 操作
jedisPoolConfig.setTestOnReturn( true );
jedisPoolConfig.setTestWhileIdle( true );
JedisPool jedisPool = new JedisPool(jedisPoolConfig, hostname, port, 3000);

poolFactory.put(key, jedisPool);
}
}
}
return poolFactory.get(key);
}
}

RedisPoolFactory

原文:https://www.cnblogs.com/maoxiangyi/p/11567203.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!