/** * 初始化 Redis 连接池 * @param props j2cache.properties * @param prefix configuration prefix * @return redis connection pool configuration object */ public final static JedisPoolConfig newPoolConfig(Properties props, String prefix) { JedisPoolConfig cfg = new JedisPoolConfig(); cfg.setMaxTotal(Integer.valueOf(props.getProperty(key(prefix,"maxTotal"), "-1"))); cfg.setMaxIdle(Integer.valueOf(props.getProperty(key(prefix,"maxIdle"), "100"))); cfg.setMaxWaitMillis(Integer.valueOf(props.getProperty(key(prefix,"maxWaitMillis"), "100"))); cfg.setMinEvictableIdleTimeMillis(Integer.valueOf(props.getProperty(key(prefix,"minEvictableIdleTimeMillis"), "864000000"))); cfg.setMinIdle(Integer.valueOf(props.getProperty(key(prefix,"minIdle"), "10"))); cfg.setNumTestsPerEvictionRun(Integer.valueOf(props.getProperty(key(prefix,"numTestsPerEvictionRun"), "10"))); cfg.setLifo(Boolean.valueOf(props.getProperty(key(prefix,"lifo"), "false"))); cfg.setSoftMinEvictableIdleTimeMillis(Integer.valueOf((String)props.getOrDefault(key(prefix,"softMinEvictableIdleTimeMillis"), "10"))); cfg.setTestOnBorrow(Boolean.valueOf(props.getProperty(key(prefix,"testOnBorrow"), "true"))); cfg.setTestOnReturn(Boolean.valueOf(props.getProperty(key(prefix,"testOnReturn"), "false"))); cfg.setTestWhileIdle(Boolean.valueOf(props.getProperty(key(prefix,"testWhileIdle"), "true"))); cfg.setTimeBetweenEvictionRunsMillis(Integer.valueOf(props.getProperty(key(prefix,"timeBetweenEvictionRunsMillis"), "300000"))); cfg.setBlockWhenExhausted(Boolean.valueOf(props.getProperty(key(prefix,"blockWhenExhausted"), "false"))); return cfg; }
private JedisHolder(SpiderConfig config) { this.config = config; this.redisIp = this.config.getRedisIp(); this.redisPort = this.config.getRedisPort(); JedisPoolConfig config1 = new JedisPoolConfig(); config1.setLifo(true); config1.setMaxIdle(8); config1.setMaxTotal(8); config1.setMaxWaitMillis(-1); config1.setMinEvictableIdleTimeMillis(1800000); config1.setMinIdle(0); config1.setNumTestsPerEvictionRun(3); config1.setSoftMinEvictableIdleTimeMillis(1800000); config1.setTestOnBorrow(false); config1.setTestWhileIdle(false); config1.setTimeBetweenEvictionRunsMillis(-1); this.jedisPool = new JedisPool(config1, this.redisIp, this.redisPort, 3000); }
private static JedisPoolConfig createJedisPoolConfig(Builder builder) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(builder.maxTotal); config.setMaxIdle(builder.maxIdle); config.setMinIdle(builder.minIdle); config.setLifo(builder.lifo); config.setFairness(builder.fairness); config.setMaxWaitMillis(builder.maxWaitMillis); config.setMinEvictableIdleTimeMillis(builder.minEvictableIdleTimeMillis); config.setSoftMinEvictableIdleTimeMillis(builder.softMinEvictableIdleTimeMillis); config.setNumTestsPerEvictionRun(builder.numTestsPerEvictionRun); config.setTestOnCreate(builder.testOnCreate); config.setTestOnBorrow(builder.testOnBorrow); config.setTestOnReturn(builder.testOnReturn); config.setTestWhileIdle(builder.testWhileIdle); config.setTimeBetweenEvictionRunsMillis(builder.timeBetweenEvictionRunsMillis); config.setEvictionPolicyClassName(builder.evictionPolicyClassName); config.setBlockWhenExhausted(builder.blockWhenExhausted); config.setJmxEnabled(builder.jmxEnabled); config.setJmxNameBase(builder.jmxNameBase); config.setJmxNamePrefix(builder.jmxNamePrefix); return config; }
private JedisPoolConfig convert(RedisPoolConfig cfg) { JedisPoolConfig jpc = new JedisPoolConfig(); jpc.setBlockWhenExhausted(cfg.isBlockWhenExhausted()); jpc.setLifo(cfg.isLifo()); jpc.setMaxIdle(cfg.getMaxIdle()); jpc.setMaxTotal(cfg.getMaxTotal()); jpc.setMaxWaitMillis(cfg.getMaxWaitMillis()); jpc.setMinEvictableIdleTimeMillis(cfg.getMinEvictableIdleTimeMillis()); jpc.setMinIdle(cfg.getMinIdle()); jpc.setNumTestsPerEvictionRun(cfg.getNumTestsPerEvictionRun()); jpc.setTestOnBorrow(cfg.isTestOnBorrow()); jpc.setTestOnReturn(cfg.isTestOnReturn()); jpc.setTestWhileIdle(cfg.isTestWhileIdle()); jpc.setTimeBetweenEvictionRunsMillis(cfg.getTimeBetweenEvictionRunsMillis()); return jpc; }