private JedisPool getInstance() { if (pool == null) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(1000); config.setMaxIdle(20); config.setMaxWaitMillis(10 * 1000l); config.setTestOnBorrow(true); config.setTestOnReturn(true); pool = new JedisPool(config, REDIS_SERVER, REDIS_PORT, 10); } return pool; }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGrids(gridCount()); JedisPoolConfig jedisPoolCfg = new JedisPoolConfig(); jedisPoolCfg.setMaxWaitMillis(20000); jedisPoolCfg.setMaxIdle(100); jedisPoolCfg.setMinIdle(1); jedisPoolCfg.setNumTestsPerEvictionRun(10); jedisPoolCfg.setTestOnBorrow(true); jedisPoolCfg.setTestOnReturn(true); jedisPoolCfg.setTestWhileIdle(true); jedisPoolCfg.setTimeBetweenEvictionRunsMillis(30000); pool = new JedisPool(jedisPoolCfg, HOST, PORT, 10000); }
config.setMaxWaitMillis(hmilyRedisConfig.getMaxWaitMillis()); config.setTestOnBorrow(hmilyRedisConfig.getTestOnBorrow()); config.setTestOnReturn(hmilyRedisConfig.getTestOnReturn()); config.setTestWhileIdle(hmilyRedisConfig.getTestWhileIdle()); config.setMinEvictableIdleTimeMillis(hmilyRedisConfig.getMinEvictableIdleTimeMillis());
config.setTestOnReturn(mythRedisConfig.getTestOnReturn());
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; }
public RedisClusterCacheStorager(Set<HostAndPort> nodes) { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(MAX_TOTAL); poolConfig.setMaxIdle(MAX_IDLE); poolConfig.setMaxWaitMillis(MAX_WAIT_MILLIS); poolConfig.setTestOnBorrow(TEST_ON_BORROW); poolConfig.setTestOnReturn(TEST_ON_RETURN); this.jedisCluster = new JedisCluster(nodes, CONNECTION_TIMEOUT, SO_TIMEOUT, MAX_REDIRECTIONS, poolConfig); }
config.setMaxWaitMillis(10000); // 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1 config.setTestOnBorrow(true); // 在获取连接的时候检查有效性, 默认false config.setTestOnReturn(false); // 调用returnObject方法时,是否进行有效检查 config.setTestWhileIdle(true); // Idle时进行连接扫描 config.setTimeBetweenEvictionRunsMillis(30000); // 表示idle object evitor两次扫描之间要sleep的毫秒数
private static JedisPool createJedisPool(String host, int port) { logger.info("init redis poll {}:{}", host, port); JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setTestOnReturn(false); poolConfig.setTestOnBorrow(false); poolConfig.setMaxTotal(DEFAULT_POOL_SIZE); poolConfig.setMaxIdle(DEFAULT_POOL_SIZE); poolConfig.setMinIdle(DEFAULT_POLL_IDLE); return new JedisPool(poolConfig, host, port, DEFAULT_TIMEOUT); } }
@Bean(name = "jedisPool") public JedisPool jedispool() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxWaitMillis(30000); // 最大等待时间 config.setMaxTotal(32); // 最大连接数 config.setMinIdle(6); // 允许最小的空闲连接数 config.setTestOnBorrow(false); // 申请到连接时是否效验连接是否有效,对性能有影响,建议关闭 config.setTestOnReturn(false); // 使用完连接放回连接池时是否效验连接是否有效,对性能有影响,建议关闭 config.setTestWhileIdle(true); // 申请到连接时,如果空闲时间大于TimeBetweenEvictionRunsMillis时间,效验连接是否有效,建议开启,对性能有效不大 config.setTimeBetweenEvictionRunsMillis(30000); //TestWhileIdle的判断依据 return new JedisPool(config, host, port, timeout); } }
public static JedisPoolConfig createJedisPoolConfig() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(MAX_ACTIVE); config.setMaxIdle(MAX_IDLE); config.setMaxWaitMillis(MAX_WAIT); config.setTestOnBorrow(TEST_ON_BORROW); config.setTestOnReturn(TEST_ON_RETURN); return config; }
@Bean(name = "poolConfig") public JedisPoolConfig initJedisPoolConfig(){ log.info("JedisPoolConfig注入开始:"); JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(maxActive); poolConfig.setMaxIdle(maxIdle); poolConfig.setMaxWaitMillis(maxWaitMillis); poolConfig.setMinIdle(minIdle); poolConfig.setTestOnBorrow(true); poolConfig.setTestOnReturn(true); poolConfig.setBlockWhenExhausted(true); return poolConfig; }
private static JedisPoolConfig buildPoolConfig() { final JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(1100); poolConfig.setMaxIdle(16); 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; }
public RedisClusterCacheStorager(Set<HostAndPort> nodes) { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(MAX_TOTAL); poolConfig.setMaxIdle(MAX_IDLE); poolConfig.setMaxWaitMillis(MAX_WAIT_MILLIS); poolConfig.setTestOnBorrow(TEST_ON_BORROW); poolConfig.setTestOnReturn(TEST_ON_RETURN); this.jedisCluster = new JedisCluster(nodes, CONNECTION_TIMEOUT, SO_TIMEOUT, MAX_REDIRECTIONS, poolConfig); }
private static JedisPoolConfig buildPoolConfig() { final JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(1100); poolConfig.setMaxIdle(16); 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; }
private JedisPoolConfig getConfig(RedisConfig redisConfig) { JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxIdle(redisConfig.getConnectionConfig().getMaxIdle()); jedisPoolConfig.setMaxTotal(redisConfig.getConnectionConfig().getMaxTotal()); jedisPoolConfig.setMaxWaitMillis(redisConfig.getConnectionConfig().getMaxWait()); jedisPoolConfig.setTestOnBorrow(true); jedisPoolConfig.setTestOnReturn(true); return jedisPoolConfig; }
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; }
private JedisPoolConfig getJedisPoolConfig() { JedisPoolConfig config = new JedisPoolConfig(); PoolSetting props = settings.getPool(); config.setMaxTotal(props.getMaxTotal()); config.setMaxIdle(props.getMaxIdle()); config.setMinIdle(props.getMinIdle()); config.setMaxWaitMillis(props.getMaxWait()); config.setTestOnBorrow(props.isTestOnBorrow()); config.setTestOnReturn(props.isTestOnReturn()); config.setTestWhileIdle(props.isTestWhileIdle()); return config; } }
/** * 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; }
/** * 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; }
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; }