Java Code Examples for redis.clients.jedis.JedisPoolConfig#setMinEvictableIdleTimeMillis()
The following examples show how to use
redis.clients.jedis.JedisPoolConfig#setMinEvictableIdleTimeMillis() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JedisConfig.java From Mars-Java with MIT License | 7 votes |
public JedisPoolConfig getJedisPoolConfig() { jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(2048); jedisPoolConfig.setMaxIdle(200); jedisPoolConfig.setMinIdle(2); jedisPoolConfig.setNumTestsPerEvictionRun(2048); jedisPoolConfig.setTimeBetweenEvictionRunsMillis(30000); jedisPoolConfig.setMinEvictableIdleTimeMillis(-1); jedisPoolConfig.setSoftMinEvictableIdleTimeMillis(10000); jedisPoolConfig.setMaxWaitMillis(10000); jedisPoolConfig.setTestOnBorrow(true); jedisPoolConfig.setTestWhileIdle(true); jedisPoolConfig.setTestOnReturn(true); jedisPoolConfig.setJmxEnabled(true); jedisPoolConfig.setBlockWhenExhausted(true); return jedisPoolConfig; }
Example 2
Source File: RedisUtils.java From nifi with Apache License 2.0 | 7 votes |
private static JedisPoolConfig createJedisPoolConfig(final PropertyContext context) { final JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(context.getProperty(RedisUtils.POOL_MAX_TOTAL).asInteger()); poolConfig.setMaxIdle(context.getProperty(RedisUtils.POOL_MAX_IDLE).asInteger()); poolConfig.setMinIdle(context.getProperty(RedisUtils.POOL_MIN_IDLE).asInteger()); poolConfig.setBlockWhenExhausted(context.getProperty(RedisUtils.POOL_BLOCK_WHEN_EXHAUSTED).asBoolean()); poolConfig.setMaxWaitMillis(context.getProperty(RedisUtils.POOL_MAX_WAIT_TIME).asTimePeriod(TimeUnit.MILLISECONDS)); poolConfig.setMinEvictableIdleTimeMillis(context.getProperty(RedisUtils.POOL_MIN_EVICTABLE_IDLE_TIME).asTimePeriod(TimeUnit.MILLISECONDS)); poolConfig.setTimeBetweenEvictionRunsMillis(context.getProperty(RedisUtils.POOL_TIME_BETWEEN_EVICTION_RUNS).asTimePeriod(TimeUnit.MILLISECONDS)); poolConfig.setNumTestsPerEvictionRun(context.getProperty(RedisUtils.POOL_NUM_TESTS_PER_EVICTION_RUN).asInteger()); poolConfig.setTestOnCreate(context.getProperty(RedisUtils.POOL_TEST_ON_CREATE).asBoolean()); poolConfig.setTestOnBorrow(context.getProperty(RedisUtils.POOL_TEST_ON_BORROW).asBoolean()); poolConfig.setTestOnReturn(context.getProperty(RedisUtils.POOL_TEST_ON_RETURN).asBoolean()); poolConfig.setTestWhileIdle(context.getProperty(RedisUtils.POOL_TEST_WHILE_IDLE).asBoolean()); return poolConfig; }
Example 3
Source File: RedisConfig.java From springboot-learn with MIT License | 6 votes |
@Bean(name = "jedis.pool.config") public JedisPoolConfig jedisPoolConfig(@Value("${spring.redis.jedis.pool.maxTotal}") int maxTotal, @Value("${spring.redis.jedis.pool.maxIdle}") int maxIdle, @Value("${spring.redis.jedis.pool.maxWaitMillis}") int maxWaitMillis, @Value("${spring.redis.jedis.pool.testOnBorrow}") boolean testOnBorrow, @Value("${spring.redis.jedis.pool.testOnReturn}") boolean testOnReturn, @Value("${spring.redis.jedis.pool.blockWhenExhausted}") boolean blockWhenExhausted, @Value("${spring.redis.jedis.pool.testWhileIdle}") boolean testWhileIdle, @Value("${spring.redis.jedis.pool.timeBetweenEvictionRunsMillis}") long timeBetweenEvictionRunsMillis, @Value("${spring.redis.jedis.pool.numTestsPerEvictionRun}") int numTestsPerEvictionRun, @Value("${spring.redis.jedis.pool.minEvictableIdleTimeMillis}") long minEvictableIdleTimeMillis) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(maxTotal); config.setMaxIdle(maxIdle); config.setMaxWaitMillis(maxWaitMillis); config.setTestOnBorrow(testOnBorrow); config.setTestOnReturn(testOnReturn); config.setBlockWhenExhausted(blockWhenExhausted); config.setTestWhileIdle(testWhileIdle); config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); config.setNumTestsPerEvictionRun(numTestsPerEvictionRun); config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); return config; }
Example 4
Source File: RedisUtils.java From J2Cache with Apache License 2.0 | 6 votes |
/** * 初始化 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; }
Example 5
Source File: RedisUtils.java From J2Cache with Apache License 2.0 | 6 votes |
/** * 初始化 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; }
Example 6
Source File: DefaultRedis.java From craft-atom with MIT License | 6 votes |
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; }
Example 7
Source File: JedisClientHelper.java From pinlater with Apache License 2.0 | 6 votes |
public JedisPool createClient(RedisClientConfig redisClientConfig, EndPoint endPoint) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxWait(redisClientConfig.getMaxWaitMillis()); config.setMaxActive(redisClientConfig.getNumConnections()); config.setMaxIdle(redisClientConfig.getNumConnections()); // Deal with idle connection eviction. config.setTestOnBorrow(false); config.setTestOnReturn(false); config.setTestWhileIdle(true); config.setMinEvictableIdleTimeMillis(5 * 60 * 1000); config.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000); config.setNumTestsPerEvictionRun(redisClientConfig.getNumConnections()); JedisPool jedisPool = new JedisPool( config, endPoint.host, endPoint.port, redisClientConfig.getSocketTimeoutMillis()); return jedisPool; }
Example 8
Source File: RedisDataSet.java From jmeter-plugins with Apache License 2.0 | 5 votes |
@Override public void testStarted(String distributedHost) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(getMaxActive()); config.setMaxIdle(getMaxIdle()); config.setMinIdle(getMinIdle()); config.setMaxWait(getMaxWait()); config.setWhenExhaustedAction((byte)getWhenExhaustedAction()); config.setTestOnBorrow(getTestOnBorrow()); config.setTestOnReturn(getTestOnReturn()); config.setTestWhileIdle(getTestWhileIdle()); config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis()); config.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun()); config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis()); config.setSoftMinEvictableIdleTimeMillis(getSoftMinEvictableIdleTimeMillis()); int port = Protocol.DEFAULT_PORT; if(!JOrphanUtils.isBlank(this.port)) { port = Integer.parseInt(this.port); } int timeout = Protocol.DEFAULT_TIMEOUT; if(!JOrphanUtils.isBlank(this.timeout)) { timeout = Integer.parseInt(this.timeout); } int database = Protocol.DEFAULT_DATABASE; if(!JOrphanUtils.isBlank(this.database)) { database = Integer.parseInt(this.database); } String password = null; if(!JOrphanUtils.isBlank(this.password)) { password = this.password; } this.pool = new JedisPool(config, this.host, port, timeout, password, database); }
Example 9
Source File: JedisIntegrationTest.java From tutorials with MIT License | 5 votes |
private JedisPoolConfig buildPoolConfig() { final JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(128); poolConfig.setMaxIdle(128); poolConfig.setMinIdle(16); poolConfig.setTestOnBorrow(true); poolConfig.setTestOnReturn(true); poolConfig.setTestWhileIdle(true); poolConfig.setMinEvictableIdleTimeMillis(Duration.ofSeconds(60).toMillis()); poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofSeconds(30).toMillis()); poolConfig.setNumTestsPerEvictionRun(3); poolConfig.setBlockWhenExhausted(true); return poolConfig; }
Example 10
Source File: RedisPools.java From pinlater with Apache License 2.0 | 5 votes |
private static JedisPool createRedisPool( String host, int port, int poolSize, int maxWaitMillis, int socketTimeoutMillis) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxWait(maxWaitMillis); config.setMaxActive(poolSize); config.setMaxIdle(poolSize); // Deal with idle connection eviction. config.setTestOnBorrow(false); config.setTestOnReturn(false); config.setTestWhileIdle(true); config.setMinEvictableIdleTimeMillis(5 * 60 * 1000); config.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000); config.setNumTestsPerEvictionRun(poolSize); JedisPool pool = new JedisPool(config, host, port, socketTimeoutMillis); // Force connection pool initialization. Jedis jedis = null; try { jedis = pool.getResource(); } catch (JedisConnectionException e) { LOG.error( String.format("Failed to get a redis connection when creating redis pool, " + "host: %s, port: %d", host, port), e); } finally { pool.returnResource(jedis); } return pool; }
Example 11
Source File: DefaultRedisConfiguration.java From spring-redis-plugin with Apache License 2.0 | 5 votes |
@Bean public JedisPoolConfig defaultJedisPoolConfig() { JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(env.getProperty("redis.maxTotal", Integer.class, 200)); jedisPoolConfig.setMaxIdle(env.getProperty("redis.maxIdle", Integer.class, 20)); jedisPoolConfig.setMinIdle(env.getProperty("redis.minIdle", Integer.class, 0)); jedisPoolConfig.setMaxWaitMillis(env.getProperty("redis.maxWait", Integer.class, 3000)); jedisPoolConfig.setMinEvictableIdleTimeMillis(env.getProperty("redis.minEvictableIdleTimeMillis", Long.class, 60000L)); jedisPoolConfig.setTimeBetweenEvictionRunsMillis(env.getProperty("redis.timeBetweenEvictionRunsMillis", Long.class, 120000L)); jedisPoolConfig.setNumTestsPerEvictionRun(env.getProperty("redis.numTestsPerEvictionRun", Integer.class, 1)); jedisPoolConfig.setTestOnBorrow(env.getProperty("redis.testOnBorrow", Boolean.class, false)); jedisPoolConfig.setTestOnReturn(env.getProperty("redis.testOnReturn", Boolean.class, false)); jedisPoolConfig.setTestWhileIdle(env.getProperty("redis.testWhileIdle", Boolean.class, true)); return jedisPoolConfig; }
Example 12
Source File: DefaultShardedRedisConfiguration.java From spring-redis-plugin with Apache License 2.0 | 5 votes |
@Bean public JedisPoolConfig defaultJedisPoolConfig() { JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(env.getProperty("redis.maxTotal", Integer.class, 200)); jedisPoolConfig.setMaxIdle(env.getProperty("redis.maxIdle", Integer.class, 20)); jedisPoolConfig.setMinIdle(env.getProperty("redis.minIdle", Integer.class, 0)); jedisPoolConfig.setMaxWaitMillis(env.getProperty("redis.maxWait", Integer.class, 3000)); jedisPoolConfig.setMinEvictableIdleTimeMillis(env.getProperty("redis.minEvictableIdleTimeMillis", Long.class, 60000L)); jedisPoolConfig.setTimeBetweenEvictionRunsMillis(env.getProperty("redis.timeBetweenEvictionRunsMillis", Long.class, 120000L)); jedisPoolConfig.setNumTestsPerEvictionRun(env.getProperty("redis.numTestsPerEvictionRun", Integer.class, 1)); jedisPoolConfig.setTestOnBorrow(env.getProperty("redis.testOnBorrow", Boolean.class, false)); jedisPoolConfig.setTestOnReturn(env.getProperty("redis.testOnReturn", Boolean.class, false)); jedisPoolConfig.setTestWhileIdle(env.getProperty("redis.testWhileIdle", Boolean.class, true)); return jedisPoolConfig; }
Example 13
Source File: RGTConfigService.java From redis-game-transaction with Apache License 2.0 | 5 votes |
public JedisPoolConfig initRediPoolConfig() throws DataConversionException { Element element = JdomUtils.getRootElemet(FileUtil.getConfigURL(GlobalConstants.RedisConfigFile.REDIS_POOL_CONIFG).getFile()); JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); int maxIdle = element.getAttribute("maxIdle").getIntValue(); boolean testWhileIdle = element.getAttribute("testWhileIdle").getBooleanValue(); int timeBetweenEvictionRunsMillis = element.getAttribute("timeBetweenEvictionRunsMillis").getIntValue(); int numTestsPerEvictionRun = element.getAttribute("numTestsPerEvictionRun").getIntValue(); int minEvictableIdleTimeMillis = element.getAttribute("minEvictableIdleTimeMillis").getIntValue(); jedisPoolConfig.setTestWhileIdle(testWhileIdle); jedisPoolConfig.setMaxIdle(maxIdle); jedisPoolConfig.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); jedisPoolConfig.setNumTestsPerEvictionRun(numTestsPerEvictionRun); jedisPoolConfig.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); return jedisPoolConfig; }
Example 14
Source File: RedisDistributeLockTest.java From azeroth with Apache License 2.0 | 5 votes |
public static void initRedisProvider() { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxIdle(1); poolConfig.setMinEvictableIdleTimeMillis(60 * 1000); poolConfig.setMaxTotal(5); poolConfig.setMaxWaitMillis(30 * 1000); String[] servers = "127.0.0.1:6379".split(","); int timeout = 3000; String password = null; int database = 0; JedisProvider<Jedis, BinaryJedis> provider = new JedisStandaloneProvider("default", poolConfig, servers, timeout, password, database, null); JedisProviderFactory.setDefaultJedisProvider(provider); }
Example 15
Source File: Client.java From JRedisBloom with BSD 2-Clause "Simplified" License | 5 votes |
/** * Create a new client to ReBloom * @param host the redis host * @param port the redis port * @param timeout connection timeout * @param poolSize the poolSize of JedisPool */ public Client(String host, int port, int timeout, int poolSize) { JedisPoolConfig conf = new JedisPoolConfig(); conf.setMaxTotal(poolSize); conf.setTestOnBorrow(false); conf.setTestOnReturn(false); conf.setTestOnCreate(false); conf.setTestWhileIdle(false); conf.setMinEvictableIdleTimeMillis(60000); conf.setTimeBetweenEvictionRunsMillis(30000); conf.setNumTestsPerEvictionRun(-1); conf.setFairness(true); pool = new JedisPool(conf, host, port, timeout); }
Example 16
Source File: BootStrap.java From MyBlog with Apache License 2.0 | 5 votes |
/*********************************************************************************************************/ //redisCluster设置 @Bean(destroyMethod = "close") public JedisCluster getJedisCluster() { JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); // 最大空闲数 jedisPoolConfig.setMaxIdle(10); // 连接池的最大数据库连接数 jedisPoolConfig.setMaxTotal(30); // 最大建立连接等待时间 jedisPoolConfig.setMaxWaitMillis(1500); // 逐出连接的最小空闲时间 默认1800000毫秒(30分钟) jedisPoolConfig.setMinEvictableIdleTimeMillis(1800000); // 每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3 jedisPoolConfig.setNumTestsPerEvictionRun(3); // 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1 jedisPoolConfig.setTimeBetweenEvictionRunsMillis(30000); // 连接空闲多久后释放,当空闲时间大于该值且空闲连接大于最大空闲连接数时释放 jedisPoolConfig.setSoftMinEvictableIdleTimeMillis(10000); // 是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个 jedisPoolConfig.setTestOnBorrow(true); // 在空闲时检查有效性, 默认false jedisPoolConfig.setTestWhileIdle(true); // 连接耗尽时是否阻塞,false报异常,true阻塞直到超时,默认true jedisPoolConfig.setBlockWhenExhausted(false); Set<HostAndPort> nodeSet = Sets.newHashSet(); nodeSet.add(new HostAndPort("127.0.0.1", 6381)); nodeSet.add(new HostAndPort("127.0.0.1", 6382)); nodeSet.add(new HostAndPort("127.0.0.1", 6383)); nodeSet.add(new HostAndPort("127.0.0.1", 6384)); nodeSet.add(new HostAndPort("127.0.0.1", 6385)); nodeSet.add(new HostAndPort("127.0.0.1", 6386)); return new JedisCluster(nodeSet, 2000, 100, jedisPoolConfig); }
Example 17
Source File: RedisConfiguration.java From heimdall with Apache License 2.0 | 5 votes |
/** * Returns a configured {@link JedisPoolConfig}. * * @return {@link JedisPoolConfig} */ public JedisPoolConfig jediPoolConfig() { final JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(property.getRedis().getMaxTotal()); poolConfig.setMaxIdle(property.getRedis().getMaxIdle()); poolConfig.setMinIdle(property.getRedis().getMinIdle()); poolConfig.setTestOnBorrow(property.getRedis().isTestOnBorrow()); poolConfig.setTestOnReturn(property.getRedis().isTestOnReturn()); poolConfig.setTestWhileIdle(property.getRedis().isTestWhileIdle()); poolConfig.setMinEvictableIdleTimeMillis(Duration.ofSeconds(property.getRedis().getMinEvictableIdleTimeSeconds()).toMillis()); poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofSeconds(property.getRedis().getTimeBetweenEvictionRunsSeconds()).toMillis()); poolConfig.setNumTestsPerEvictionRun(property.getRedis().getNumTestsPerEvictionRun()); poolConfig.setBlockWhenExhausted(property.getRedis().isBlockWhenExhausted()); return poolConfig; }
Example 18
Source File: RedisConfiguration.java From heimdall with Apache License 2.0 | 5 votes |
/** * Configures and returns a {@link JedisPoolConfig}. * * @return {@link JedisPoolConfig} */ public JedisPoolConfig jediPoolConfig() { final JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(property.getRedis().getMaxTotal()); poolConfig.setMaxIdle(property.getRedis().getMaxIdle()); poolConfig.setMinIdle(property.getRedis().getMinIdle()); poolConfig.setTestOnBorrow(property.getRedis().isTestOnBorrow()); poolConfig.setTestOnReturn(property.getRedis().isTestOnReturn()); poolConfig.setTestWhileIdle(property.getRedis().isTestWhileIdle()); poolConfig.setMinEvictableIdleTimeMillis(Duration.ofSeconds(property.getRedis().getMinEvictableIdleTimeSeconds()).toMillis()); poolConfig.setTimeBetweenEvictionRunsMillis(Duration.ofSeconds(property.getRedis().getTimeBetweenEvictionRunsSeconds()).toMillis()); poolConfig.setNumTestsPerEvictionRun(property.getRedis().getNumTestsPerEvictionRun()); poolConfig.setBlockWhenExhausted(property.getRedis().isBlockWhenExhausted()); return poolConfig; }
Example 19
Source File: RedisSource.java From ingestion with Apache License 2.0 | 4 votes |
private void init() { try { JedisPoolConfig poolConfig = new JedisPoolConfig(); String prop; if((prop = poolProps.get(CONF_TESTONBORROW)) == null){ poolConfig.setTestOnBorrow(DEFAULT_TESTONBORROW); } else { log.info("Setting testOnBorrow property to " + prop); poolConfig.setTestOnBorrow(Boolean.valueOf(prop)); } if((prop = poolProps.get(CONF_MAXTOTAL)) == null){ poolConfig.setMaxTotal(DEFAULT_MAXTOTAL); } else { log.info("Setting maxTotal property to " + prop); poolConfig.setMaxTotal(Integer.valueOf(prop)); } if((prop = poolProps.get(CONF_MAXIDLE)) == null){ poolConfig.setMaxTotal(DEFAULT_MAXIDLE); } else { log.info("Setting maxIdle property to " + prop); poolConfig.setMaxIdle(Integer.valueOf(prop)); } if((prop = poolProps.get(CONF_MINIDLE)) == null){ poolConfig.setMinIdle(DEFAULT_MINIDLE); } else { log.info("Setting minIdle property to " + prop); poolConfig.setMinIdle(Integer.valueOf(prop)); } if((prop = poolProps.get(CONF_MAXWAITINMILLIS)) == null){ poolConfig.setMaxWaitMillis(DEFAULT_MAXWAITINMILLIS); } else { log.info("Setting maxWaitInMillis property to " + prop); poolConfig.setMaxWaitMillis(Integer.valueOf(prop)); } if((prop = poolProps.get(CONF_TESTWHILEIDLE)) == null){ poolConfig.setTestWhileIdle(DEFAULT_TESTWHILEIDLE); } else { log.info("Setting testWhileIdle property to " + prop); poolConfig.setTestWhileIdle(Boolean.valueOf(prop)); } if((prop = poolProps.get(CONF_TESTONRETURN)) == null){ poolConfig.setTestOnReturn(DEFAULT_TESTONRETURN); } else { log.info("Setting testOnReturn property to " + prop); poolConfig.setTestOnReturn(Boolean.valueOf(prop)); } if((prop = poolProps.get(CONF_MINEVICTABLEIDLETIMEINMILLIS)) == null){ poolConfig.setMinEvictableIdleTimeMillis(DEFAULT_MINEVICTABLEIDLETIMEINMILLIS); } else { log.info("Setting minEvictableIdleTimeInMillis property to " + prop); poolConfig.setMinEvictableIdleTimeMillis(Integer.valueOf(prop)); } if((prop = poolProps.get(CONF_TIMEBETWEETNEVICTIONRUNSMILLIS)) == null){ poolConfig.setTimeBetweenEvictionRunsMillis(DEFAULT_TIMEBETWEETNEVICTIONRUNSMILLIS); } else { log.info("Setting timeBetweenEvictionRunMillis property to " + prop); poolConfig.setTimeBetweenEvictionRunsMillis(Integer.valueOf(prop)); } if((prop = poolProps.get(CONF_NUMTESTSPEREVICTIONRUN)) == null){ poolConfig.setNumTestsPerEvictionRun(DEFAULT_NUMTESTSPEREVICTIONRUN); } else { log.info("Setting numTestsPerEvictionRun property to " + prop); poolConfig.setNumTestsPerEvictionRun(Integer.valueOf(prop)); } // create JEDIS pool this.jedisPool = new JedisPool(poolConfig, host, port); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }