Java Code Examples for redis.clients.jedis.JedisPoolConfig#setBlockWhenExhausted()
The following examples show how to use
redis.clients.jedis.JedisPoolConfig#setBlockWhenExhausted() .
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: RedisEventLoopTest.java From fastjgame with Apache License 2.0 | 8 votes |
private static RedisEventLoop newRedisEventLoop() { final JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(1); config.setMaxTotal(5); config.setTestOnBorrow(true); config.setTestOnReturn(true); config.setBlockWhenExhausted(true); config.setMaxWaitMillis(10); // 测试时不使用哨兵 final JedisPool jedisPool = new JedisPool(config, "localhost", 6379); final RedisEventLoop redisEventLoop = new RedisEventLoop(null, new DefaultThreadFactory("RedisEventLoop"), RejectedExecutionHandlers.abort(), jedisPool); redisEventLoop.terminationFuture().addListener(future -> jedisPool.close()); return redisEventLoop; }
Example 2
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 3
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 4
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 5
Source File: RedisDatabase.java From MineCloud with ISC License | 6 votes |
@Override public void setup() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(20); config.setMinIdle(5); config.setMaxIdle(10); config.setMaxWaitMillis(200L); config.setBlockWhenExhausted(false); String host = credentials.hosts()[0]; int port = 6379; if (host.split(":").length == 2) { try { port = Integer.parseInt(host.split(":")[1]); } catch (NumberFormatException ignored) { MineCloud.logger().warning("Host " + host + " has an invalid port!"); } } pool = credentials.password() != null && credentials.password().length > 0 ? new JedisPool(config, host, port, 1000, new String(credentials.password())) : new JedisPool(config, host, port, 1000); }
Example 6
Source File: JedisFactory.java From moon-api-gateway with MIT License | 6 votes |
@Override public void afterPropertiesSet() { JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(jedisConfig.getMaxTotal()); jedisPoolConfig.setMaxWaitMillis(jedisConfig.getMaxWaitMillis()); jedisPoolConfig.setMaxIdle(jedisConfig.getMaxIdle()); jedisPoolConfig.setMinIdle(jedisConfig.getMinIdle()); jedisPoolConfig.setNumTestsPerEvictionRun(jedisConfig.getNumTestsPerEvictionRun()); jedisPoolConfig.setTimeBetweenEvictionRunsMillis(jedisConfig.getTimeBetweenEvictionRunsMillis()); jedisPoolConfig.setBlockWhenExhausted(jedisConfig.isBlockWhenExhausted()); jedisPoolConfig.setTestOnBorrow(jedisConfig.isTestOnBorrow()); jedisPoolConfig.setTestOnReturn(jedisConfig.isTestOnReturn()); jedisPoolConfig.setTestWhileIdle(jedisConfig.isTestWhileIdle()); String jedisHost = jedisConfig.getHost(); int jedisPort = jedisConfig.getPort(); int jedisTimeout = jedisConfig.getTimeout(); int jedisDatabase = jedisConfig.getDatabase(); jedisPool = new JedisPool(jedisPoolConfig, jedisHost, jedisPort, jedisTimeout, null, jedisDatabase); }
Example 7
Source File: RedisPoolConfiguration.java From seed with Apache License 2.0 | 6 votes |
@Bean public JedisPool getPool(){ JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(this.maxTotal); config.setMaxIdle(this.maxIdle); config.setMinIdle(this.minIdle); config.setBlockWhenExhausted(true); config.setMaxWaitMillis(this.maxWaitMillis); config.setTestOnBorrow(false); config.setTestOnReturn(false); String[] parts = StringUtils.split(this.nodes.get(0), ":"); JedisPool pool = new JedisPool(config, parts[0], Integer.parseInt(parts[1]), this.connectionTimeout, this.password); for(int i=0; i<this.minIdle; i++){ Jedis jedis = pool.getResource(); jedis.ping(); jedis.close(); } return pool; }
Example 8
Source File: RedisConfig.java From demo-project with MIT License | 6 votes |
@Bean public JedisConnectionFactory jedisConnectionFactory() { logger.info("jedisConnectionFactory:初始化了"); JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(maxIdle); config.setMinIdle(minIdle); config.setMaxWaitMillis(maxWaitMillis); config.setMaxTotal(maxActive); //链接耗尽时是否阻塞,默认true config.setBlockWhenExhausted(true); //是否启用pool的jmx管理功能,默认true config.setJmxEnabled(true); JedisConnectionFactory factory = new JedisConnectionFactory(); factory.setPoolConfig(config); factory.setHostName(host); factory.setPort(port); factory.setPassword(password); factory.setDatabase(database); factory.setTimeout(timeout); return factory; }
Example 9
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 10
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 11
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 12
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 13
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 14
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 15
Source File: RedisPool.java From redis-distributed-lock with Apache License 2.0 | 5 votes |
private static void init() { maxTotal = Integer.parseInt(PropertiesUtil.getProperty("redis.max.total", "20")); maxIdle = Integer.parseInt(PropertiesUtil.getProperty("redis.max.idle","20")); minIdle = Integer.parseInt(PropertiesUtil.getProperty("redis.min.idle","10")); testOnBorrow = Boolean.parseBoolean(PropertiesUtil.getProperty("redis.test.borrow","true")); testOnReturn = Boolean.parseBoolean(PropertiesUtil.getProperty("redis.test.return","true")); redisTimeout = Integer.valueOf(PropertiesUtil.getProperty("redis.server.timeout", "3000")); redisIp = PropertiesUtil.getProperty("redis.ip"); if (redisIp == null) { throw new RuntimeException("请检查redis服务端ip配置项redis.ip是否配置"); } redisPort = Integer.parseInt(PropertiesUtil.getProperty("redis.port")); if (redisPort == null) { throw new RuntimeException("请检查redis服务端port配置项redis.port是否配置"); } JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(maxTotal); config.setMaxIdle(maxIdle); config.setMinIdle(minIdle); config.setTestOnBorrow(testOnBorrow); config.setTestOnReturn(testOnReturn); /**连接耗尽的时候,是否阻塞,false会抛出异常,true阻塞直到超时。默认为true*/ config.setBlockWhenExhausted(true); pool = new JedisPool(config, redisIp, redisPort, redisTimeout); }
Example 16
Source File: RedisPool.java From mmall-kay-Java with Apache License 2.0 | 5 votes |
private static void initPool() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(maxTotal); config.setMaxIdle(maxIdle); config.setMinIdle(minIdle); config.setBlockWhenExhausted(true); //资源耗尽时是否阻塞 config.setTestOnBorrow(testOnborrow); config.setTestOnReturn(testOnReturn); pool = new JedisPool(config, host, port, 1000 * 2); }
Example 17
Source File: RedisStore.java From datacollector with Apache License 2.0 | 5 votes |
public RedisStore(RedisLookupConfig conf) { this.conf = conf; final JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setBlockWhenExhausted(true); pool = new JedisPool(poolConfig, URI.create(conf.uri), conf.connectionTimeout * 1000); // connectionTimeout value is in seconds }
Example 18
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 19
Source File: RedisCacheConfig.java From jseckill with Apache License 2.0 | 5 votes |
@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; }
Example 20
Source File: RedisPool.java From seconds-kill with MIT License | 5 votes |
private static void initPool() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(maxTotal); config.setMaxIdle(maxIdle); config.setTestOnBorrow(testOnBorrow); config.setBlockWhenExhausted(true); config.setMaxWaitMillis(maxWait); pool = new JedisPool(config, redisIP, redisPort, 1000 * 2); }