Java Code Examples for redis.clients.jedis.JedisPoolConfig#setMinIdle()
The following examples show how to use
redis.clients.jedis.JedisPoolConfig#setMinIdle() .
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: 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 2
Source File: JedisManagerFactory.java From es-service-parent with Apache License 2.0 | 6 votes |
/** * 根据配置创建 * * @return */ private static JedisManager createJedisManager() { // 池基本配置 JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(Conf.getInt("redis.maxIdle")); config.setMinIdle(Conf.getInt("redis.minIdle")); config.setMaxWaitMillis(Conf.getLong("redis.maxWaitMillis")); config.setTestOnBorrow(Conf.getBoolean("redis.testOnBorrow")); List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); // 链接 shards.add(new JedisShardInfo(Conf.getString("redis.host"), Conf.getInt("redis.port"), Conf .getInt("redis.timeout"))); // 构造池 ShardedJedisPool shardedJedisPool = new ShardedJedisPool(config, shards); return new JedisManager(shardedJedisPool); }
Example 3
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 4
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 5
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 6
Source File: JedisServiceImpl.java From jframe with Apache License 2.0 | 5 votes |
JedisPoolConfig createPoolConfig(PropsConf conf, String id) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(conf.getConfInt(id, "redis.conn.maxTotal", "200")); config.setMaxIdle(conf.getConfInt(id, "redis.conn.maxIdle", "100")); config.setMinIdle(conf.getConfInt(id, "redis.conn.minIdle", "1")); config.setMaxWaitMillis(conf.getConfLong(id, "redis.conn.maxWaitMillis", "3000")); // config.setTestOnReturn(true); return config; }
Example 7
Source File: RedisPool.java From mmall20180107 with Apache License 2.0 | 5 votes |
private static void initPool(){ JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(maxTotal); jedisPoolConfig.setMaxIdle(maxIdle); jedisPoolConfig.setMinIdle(minIdle); jedisPoolConfig.setTestOnBorrow(testOnBorrow); jedisPoolConfig.setTestOnReturn(testOnReturn); jedisPoolConfig.setBlockWhenExhausted(true);//连接耗尽的时候,是否阻塞,false会抛出异常,true阻塞直到超时。默认为true。 jedisPool = new JedisPool(jedisPoolConfig,redisIp,redisPort,2000); }
Example 8
Source File: JedisPoolFactoryBean.java From juice with Apache License 2.0 | 5 votes |
@Override public JedisPool getObject() throws Exception { logger.info("jedis init host:{} port:{} timeout:{} password:{}", host, port, timeout, password); if (port==null) { port = DEFAULT_PORT; } if (timeout==null) { timeout = DEFAULT_TIMEOUT; } logger.info("jedis pool init maxTotal:{} maxIdle:{} minIdle:{}", maxTotal, maxIdle, minIdle); //pool config JedisPoolConfig poolConfig = new JedisPoolConfig(); if (maxTotal!=null) { poolConfig.setMaxTotal(maxTotal); } if (maxIdle!=null) { poolConfig.setMaxIdle(maxIdle); } if (minIdle!=null) { poolConfig.setMinIdle(minIdle); } poolConfig.setTestOnBorrow(testOnBorrow == null ? Boolean.FALSE : testOnBorrow); poolConfig.setTestOnReturn(testOnReturn == null ? Boolean.FALSE : testOnReturn); poolConfig.setTestWhileIdle(testWhileIdle == null ? Boolean.TRUE : testWhileIdle); this.pool = new JedisPool(poolConfig, host, port, timeout, password); return pool; }
Example 9
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 10
Source File: RedisAutoConfiguration.java From MaxKey with Apache License 2.0 | 5 votes |
/** * RedisConnectionFactory. * @param host String * @param port int * @param timeout int * @param password String * @param maxActive int * @param maxWait int * @param maxIdle int * @param minIdle int * @return RedisConnectionFactory */ @Bean public RedisConnectionFactory redisConnectionFactory( @Value("${spring.redis.host}") String host, @Value("${spring.redis.port}") int port, @Value("${spring.redis.timeout}") int timeout, @Value("${spring.redis.password}") String password, @Value("${spring.redis.lettuce.pool.max-active}") int maxActive, @Value("${spring.redis.jedis.pool.max-wait}") int maxWait, @Value("${spring.redis.jedis.pool.max-idle}") int maxIdle, @Value("${spring.redis.lettuce.pool.min-idle}") int minIdle) { _logger.debug("RedisConnectionFactory init ."); RedisConnectionFactory factory = new RedisConnectionFactory(); factory.setHostName(host); factory.setPort(port); factory.setTimeOut(timeout); factory.setPassword(password); JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxIdle(maxIdle); poolConfig.setMinIdle(minIdle); poolConfig.setMaxTotal(maxActive); poolConfig.setMaxWaitMillis(maxWait); factory.setPoolConfig(poolConfig); return factory; }
Example 11
Source File: RedisConnectionPoolConfig.java From netty-cookbook with Apache License 2.0 | 5 votes |
public JedisPoolConfig getJedisPoolConfig() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(this.maxTotal); config.setMaxIdle(this.maxIdle); config.setMinIdle(this.minIdle); config.setMaxWaitMillis(this.maxWaitMillis); config.setNumTestsPerEvictionRun(this.numTestsPerEvictionRun); config.setTestOnBorrow(this.testOnBorrow); config.setTestOnReturn(this.testOnReturn); config.setTestWhileIdle(this.testWhileIdle); config.setTimeBetweenEvictionRunsMillis(this.timeBetweenEvictionRunsMillis); return config; }
Example 12
Source File: RedisConnectionPoolConfig.java From netty-cookbook with Apache License 2.0 | 5 votes |
public JedisPoolConfig getJedisPoolConfig() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(this.maxTotal); config.setMaxIdle(this.maxIdle); config.setMinIdle(this.minIdle); config.setMaxWaitMillis(this.maxWaitMillis); config.setNumTestsPerEvictionRun(this.numTestsPerEvictionRun); config.setTestOnBorrow(this.testOnBorrow); config.setTestOnReturn(this.testOnReturn); config.setTestWhileIdle(this.testWhileIdle); config.setTimeBetweenEvictionRunsMillis(this.timeBetweenEvictionRunsMillis); return config; }
Example 13
Source File: RedisConnectionPoolConfig.java From netty-cookbook with Apache License 2.0 | 5 votes |
public JedisPoolConfig getJedisPoolConfig() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(this.maxTotal); config.setMaxIdle(this.maxIdle); config.setMinIdle(this.minIdle); config.setMaxWaitMillis(this.maxWaitMillis); config.setNumTestsPerEvictionRun(this.numTestsPerEvictionRun); config.setTestOnBorrow(this.testOnBorrow); config.setTestOnReturn(this.testOnReturn); config.setTestWhileIdle(this.testWhileIdle); config.setTimeBetweenEvictionRunsMillis(this.timeBetweenEvictionRunsMillis); return config; }
Example 14
Source File: RedisManager.java From grain with MIT License | 5 votes |
/** * 初始化redis * * @param ip * ip地址 * @param port * 端口 * @param log * 日志可以为null */ public static void init(String ip, int port, ILog log) { RedisManager.log = log; JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(2000); jedisPoolConfig.setMaxIdle(200); jedisPoolConfig.setMinIdle(0); jedisPoolConfig.setTestOnBorrow(true); jedisPool = new JedisPool(jedisPoolConfig, ip, port); serializer = new SerializingConverter(log); deserializer = new DeserializingConverter(log); }
Example 15
Source File: JedisFactory.java From droptools with Apache License 2.0 | 5 votes |
public JedisPool build(Environment environment) { final JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMinIdle(getMinIdle()); poolConfig.setMaxIdle(getMaxIdle()); poolConfig.setMaxTotal(getMaxTotal()); poolConfig.setMaxWaitMillis(getTimeout()); // Use configured timeout value as the time to wait for a connection final JedisPool pool = new JedisPool(poolConfig, getHost(), getPort(), getTimeout(), getPassword(), ssl); environment.lifecycle().manage(new JedisPoolManager(pool)); return pool; }
Example 16
Source File: RedisConfig.java From SpringBoot-Home with Apache License 2.0 | 5 votes |
@Bean public JedisPool redisPoolFactory() { JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxIdle(maxIdle); jedisPoolConfig.setMaxWaitMillis(maxWait); jedisPoolConfig.setMinIdle(minIdle); JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password); return jedisPool; }
Example 17
Source File: DelegateCacheConfiguration.java From jeesuite-libs with Apache License 2.0 | 5 votes |
@Bean(name = "jedisPoolConfig") public JedisPoolConfig jedisPoolConfig() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(cacheProperties.getMaxPoolSize()); config.setMaxIdle(cacheProperties.getMaxPoolIdle()); config.setMinIdle(cacheProperties.getMinPoolIdle()); config.setMaxWaitMillis(cacheProperties.getMaxPoolWaitMillis()); return config; }
Example 18
Source File: RedisJedisManager.java From calcite with Apache License 2.0 | 5 votes |
public RedisJedisManager(String host, int port, int database, String password) { JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(maxTotal); jedisPoolConfig.setMaxIdle(maxIdle); jedisPoolConfig.setMinIdle(minIdle); this.host = host; this.port = port; this.database = database; this.password = password; this.jedisPoolConfig = jedisPoolConfig; this.jedisPoolCache = CacheBuilder.newBuilder() .removalListener(new JedisPoolRemovalListener()) .build(CacheLoader.from(this::createConsumer)); }
Example 19
Source File: JedisSampleMain.java From pepper-metrics with Apache License 2.0 | 5 votes |
public static void testJedis() throws InterruptedException { log.info("testJedis()"); JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(300); config.setMaxIdle(10); config.setMinIdle(5); config.setMaxWaitMillis(6000); config.setTestOnBorrow(false); config.setTestOnReturn(false); config.setTestWhileIdle(true); config.setTestOnCreate(false); log.info("init JedisPoolConfig: {}", config.toString()); final String namespace = "myns"; JedisPropsHolder.NAMESPACE.set(namespace); PjedisPool jedisPool = new PjedisPool(config, "192.168.100.221", 6379); JedisHealthTracker.addJedisPool(namespace, jedisPool); for (int j = 0; j < 100; j++) { for (int i = 0; i < 10; i++) { try (Jedis jedis = jedisPool.getResource()) { jedis.set("hello", "robin"); } } log.info(String.format("%s NumActive:%s NumIdle:%s", j, jedisPool.getNumActive(), jedisPool.getNumIdle())); TimeUnit.SECONDS.sleep(1); } }
Example 20
Source File: RedisRegistry.java From dubbox with Apache License 2.0 | 4 votes |
public RedisRegistry(URL url) { super(url); if (url.isAnyHost()) { throw new IllegalStateException("registry address == null"); } //GenericObjectPool.Config config = new GenericObjectPool.Config(); //config.testOnBorrow = url.getParameter("test.on.borrow", true); //config.testOnReturn = url.getParameter("test.on.return", false); //config.testWhileIdle = url.getParameter("test.while.idle", false); JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setTestOnBorrow(url.getParameter("test.on.borrow", true)); jedisPoolConfig.setTestOnReturn(url.getParameter("test.on.return", false)); jedisPoolConfig.setTestWhileIdle(url.getParameter("test.while.idle", false)); if (url.getParameter("max.idle", 0) > 0) //config.maxIdle = url.getParameter("max.idle", 0); jedisPoolConfig.setMaxIdle(url.getParameter("max.idle", 0)); if (url.getParameter("min.idle", 0) > 0) //config.minIdle = url.getParameter("min.idle", 0); jedisPoolConfig.setMinIdle(url.getParameter("min.idle", 0)); if (url.getParameter("max.active", 0) > 0) //config.maxActive = url.getParameter("max.active", 0); jedisPoolConfig.setMaxTotal(url.getParameter("max.active", 0)); if (url.getParameter("max.wait", 0) > 0) //config.maxWait = url.getParameter("max.wait", 0); jedisPoolConfig.setMaxWaitMillis(url.getParameter("max.wait", 0)); if (url.getParameter("num.tests.per.eviction.run", 0) > 0) //config.numTestsPerEvictionRun = url.getParameter("num.tests.per.eviction.run", 0); jedisPoolConfig.setNumTestsPerEvictionRun(url.getParameter("num.tests.per.eviction.run", 0)); if (url.getParameter("time.between.eviction.runs.millis", 0) > 0) //config.timeBetweenEvictionRunsMillis = url.getParameter("time.between.eviction.runs.millis", 0); jedisPoolConfig.setTimeBetweenEvictionRunsMillis(url.getParameter("time.between.eviction.runs.millis", 0)); if (url.getParameter("min.evictable.idle.time.millis", 0) > 0) //config.minEvictableIdleTimeMillis = url.getParameter("min.evictable.idle.time.millis", 0); jedisPoolConfig.setSoftMinEvictableIdleTimeMillis(url.getParameter("min.evictable.idle.time.millis", 0)); String cluster = url.getParameter("cluster", "failover"); if (! "failover".equals(cluster) && ! "replicate".equals(cluster)) { throw new IllegalArgumentException("Unsupported redis cluster: " + cluster + ". The redis cluster only supported failover or replicate."); } replicate = "replicate".equals(cluster); List<String> addresses = new ArrayList<String>(); addresses.add(url.getAddress()); String[] backups = url.getParameter(Constants.BACKUP_KEY, new String[0]); if (backups != null && backups.length > 0) { addresses.addAll(Arrays.asList(backups)); } // 增加Redis密码支持 String password = url.getPassword(); for (String address : addresses) { int i = address.indexOf(':'); String host; int port; if (i > 0) { host = address.substring(0, i); port = Integer.parseInt(address.substring(i + 1)); } else { host = address; port = DEFAULT_REDIS_PORT; } if (StringUtils.isEmpty(password)) { this.jedisPools.put(address, new JedisPool(jedisPoolConfig, host, port, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT))); } else { // 使用密码连接。 此处要求备用redis与主要redis使用相同的密码 this.jedisPools.put(address, new JedisPool(jedisPoolConfig, host, port, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), password)); } } this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD); String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT); if (! group.startsWith(Constants.PATH_SEPARATOR)) { group = Constants.PATH_SEPARATOR + group; } if (! group.endsWith(Constants.PATH_SEPARATOR)) { group = group + Constants.PATH_SEPARATOR; } this.root = group; this.expirePeriod = url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_SESSION_TIMEOUT); this.expireFuture = expireExecutor.scheduleWithFixedDelay(new Runnable() { public void run() { try { deferExpired(); // 延长过期时间 } catch (Throwable t) { // 防御性容错 logger.error("Unexpected exception occur at defer expire time, cause: " + t.getMessage(), t); } } }, expirePeriod / 2, expirePeriod / 2, TimeUnit.MILLISECONDS); }