/** * 初始化Redis连接池 */ private static void initialPool() { try { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(MAX_ACTIVE); config.setMaxIdle(MAX_IDLE); config.setMaxWaitMillis(MAX_WAIT); config.setTestOnBorrow(TEST_ON_BORROW); jedisPool = new JedisPool(config, IP, PORT, TIMEOUT); } catch (Exception e) { LOGGER.error("First create JedisPool error : " + e); } }
@Bean public JedisPool redisPoolFactory() { JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxIdle(maxIdle); jedisPoolConfig.setMaxWaitMillis(maxWaitMillis); if (StringUtils.isNotBlank(password)) { return new JedisPool(jedisPoolConfig, host, port, timeout, password); } else { return new JedisPool(jedisPoolConfig, host, port, timeout); } }
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; }
@Bean public JedisPool JedisPoolFactory() { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxIdle(redisConfig.getPoolMaxIdle()); poolConfig.setMaxTotal(redisConfig.getPoolMaxTotal()); poolConfig.setMaxWaitMillis(redisConfig.getPoolMaxWait() * 1000); JedisPool jp = new JedisPool(poolConfig, redisConfig.getHost(), redisConfig.getPort(), redisConfig.getTimeout()*1000, redisConfig.getPassword(), 0); return jp; }
public static RedisCache create(final RedisCacheConfig config) { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(config.getMaxTotalConnections()); poolConfig.setMaxIdle(config.getMaxIdleConnections()); poolConfig.setMinIdle(config.getMinIdleConnections()); JedisPool pool = new JedisPool(poolConfig, config.getHost(), config.getPort(), config.getTimeout()); return new RedisCache(pool, config); }
/** {@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); }
private void buildJedisPool(final HmilyRedisConfig hmilyRedisConfig) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(hmilyRedisConfig.getMaxIdle()); config.setMinIdle(hmilyRedisConfig.getMinIdle()); config.setMaxTotal(hmilyRedisConfig.getMaxTotal());
private void buildJedisPool(final MythRedisConfig mythRedisConfig) { LogUtil.debug(LOGGER, () -> "myth begin init redis...."); JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(mythRedisConfig.getMaxIdle());
/** * @param redisProperties * @return */ public static JedisPool createJedisPool(Properties redisProperties) { String host = redisProperties.getProperty("redis.host", "localhost"); int port = Integer.valueOf(redisProperties.getProperty("redis.port", "6379")); int timeout = Integer.valueOf(redisProperties.getProperty("redis.timeout", "3000")); int maxidle = Integer.valueOf(redisProperties.getProperty("redis.maxidle", "10")); String password = redisProperties.getProperty("redis.password"); JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(maxidle); return new JedisPool(config, host, port, timeout, password); } }
/** * @param redisProperties * @return */ public static JedisPool createJedisPool(Properties redisProperties) { String host = redisProperties.getProperty("redis.host", "localhost"); int port = Integer.valueOf(redisProperties.getProperty("redis.port", "6379")); int timeout = Integer.valueOf(redisProperties.getProperty("redis.timeout", "3000")); int maxidle = Integer.valueOf(redisProperties.getProperty("redis.maxidle", "10")); String password = redisProperties.getProperty("redis.password"); JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(maxidle); return new JedisPool(config, host, port, timeout, password); } }
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 static void initPool(){ JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(maxActive); config.setMaxIdle(maxIdle); config.setMaxWaitMillis(maxWait); config.setTestOnBorrow(false); jedisPool = new JedisPool(config, redisIp, redisPort, 10000, password); } // 从连接池获取redis连接
private JedisPoolConfig onPoolConfig(final byte WHEN_EXHAUSTED_FAIL, String maxActivePerNode, String maxIdlePerNode, String minIdlePerNode, String maxTotal) { if (!StringUtils.isBlank(maxActivePerNode) && StringUtils.isNumeric(maxActivePerNode)) { logger.info("configuring connection pool"); JedisPoolConfig poolConfig = new JedisPoolConfig(); if (maxTotal != null && StringUtils.isNumeric(maxTotal)) { poolConfig.setMaxTotal(Integer.valueOf(maxTotal)); } if (maxIdlePerNode != null && StringUtils.isNumeric(maxIdlePerNode)) { poolConfig.setMaxIdle(Integer.valueOf(maxIdlePerNode)); } if (minIdlePerNode != null && StringUtils.isNumeric(minIdlePerNode)) { poolConfig.setMinIdle(Integer.parseInt(minIdlePerNode)); } if (maxActivePerNode != null && StringUtils.isNumeric(maxActivePerNode)) { //poolConfig.setWhenExhaustedAction(WHEN_EXHAUSTED_FAIL); poolConfig.setBlockWhenExhausted(true); } return poolConfig; } return null; }
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); }
/** * Create a Jedis poll with pippo settings. URL format: * 'redis://[:password@]host[:port][/db-number][?option=value]' * * @param settings pippo settings * @return Jedis pool */ public static JedisPool create(final PippoSettings settings) { String host = settings.getString(HOST, Protocol.DEFAULT_HOST).trim(); int minIdle = settings.getInteger(MIN_IDLE, GenericObjectPoolConfig.DEFAULT_MIN_IDLE); int maxIdle = settings.getInteger(MAX_IDLE, GenericObjectPoolConfig.DEFAULT_MAX_IDLE); int maxTotal = settings.getInteger(MAX_TOTAL, GenericObjectPoolConfig.DEFAULT_MAX_TOTAL); JedisPoolConfig config = new JedisPoolConfig(); config.setMinIdle(minIdle); config.setMaxIdle(maxIdle); config.setMaxTotal(maxTotal); try { return new JedisPool(config, new URI(host)); } catch (URISyntaxException e) { throw new PippoRuntimeException("Malformed redis URI", e); } }
config.setMaxIdle(50); config.setMinIdle(8); config.setMaxWaitMillis(10000); // 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1
jedisPoolConfig.setMaxIdle(8);
public JedisPoolApacheImpl(String host, int port, int timeout, int maxActive, String password) { JedisPoolConfig poolConfig = new JedisPoolConfig(); // poolConfig.setMaxActive(maxActive); poolConfig.setMaxTotal(maxActive); poolConfig.setMaxIdle(maxActive); // poolConfig.setMinEvictableIdleTimeMillis(24 * 3600 * 1000); poolConfig.setMinEvictableIdleTimeMillis(-1);// ahai 20131024 已建立的连接不回收,高并发时建立连接会很耗资源 // poolConfig.setTimeBetweenEvictionRunsMillis(-1); pool = new JedisPool(poolConfig, host, port, timeout, password); // System.err.println("pool:"+pool); }
@Bean public JedisPool JedisPoolFactory() { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxIdle(redisConfig.getPoolMaxIdle()); poolConfig.setMaxTotal(redisConfig.getPoolMaxTotal()); poolConfig.setMaxWaitMillis(redisConfig.getPoolMaxWait() * 1000); JedisPool jp = new JedisPool(poolConfig, redisConfig.getHost(), redisConfig.getPort(), redisConfig.getTimeout()*1000, redisConfig.getPassword(), 0); return jp; }
protected JedisPoolConfig defaultPoolConfig() { JedisPoolConfig config = new JedisPoolConfig(); config.setMinIdle(AppInfo.getInt("sumk.redis.minidle", 1)); config.setMaxIdle(AppInfo.getInt("sumk.redis.maxidle", 20)); config.setMaxTotal(AppInfo.getInt("sumk.redis.maxtotal", 100)); config.setTestWhileIdle(true); config.setTimeBetweenEvictionRunsMillis(AppInfo.getInt("sumk.redis.timebetweenevictionrunsmillis", 5 * 60000)); config.setNumTestsPerEvictionRun(AppInfo.getInt("sumk.redis.numtestsperevictionrun", 3)); return config; }