Java Code Examples for redis.clients.jedis.JedisPoolConfig#setMaxWaitMillis()
The following examples show how to use
redis.clients.jedis.JedisPoolConfig#setMaxWaitMillis() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: RedisCacheConfiguration.java From NetworkDisk_Storage with GNU General Public License v2.0 | 5 votes |
public JedisPool getRedisPoolFactory() { logger.info("JedisPool注入成功!!"); logger.info("redis地址:" + host + ":" + port); JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxIdle(maxIdle); jedisPoolConfig.setMaxWaitMillis(maxWaitMillis); JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password); return jedisPool; }
Example 8
Source File: JedisPoolConfigFactory.java From AsuraFramework with Apache License 2.0 | 5 votes |
public static JedisPoolConfig createJedisPoolConfig() { final JedisPoolConfig config = new JedisPoolConfig(); config.setMaxWaitMillis(maxWait()); config.setMaxIdle(1); config.setMaxTotal(maxActive()); return config; }
Example 9
Source File: DFRedisUtil.java From dfactor with MIT License | 5 votes |
public static JedisPool createJedisPool(String host, int port, String auth, int maxTotal, int maxIdle, int minIdle, int connTimeoutMilli, int borrowTimeoutMilli){ JedisPoolConfig config = new JedisPoolConfig(); //如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。 config.setMaxTotal(maxTotal); //控制一个pool最多有多少个状态为idle(空闲的)的jedis实例。 config.setMaxIdle(maxIdle); config.setMinIdle(minIdle); //表示当borrow(引入)一个jedis实例时,最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException; config.setMaxWaitMillis(borrowTimeoutMilli); //在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的; config.setTestOnBorrow(true); return new JedisPool(config, host, port, connTimeoutMilli, auth); }
Example 10
Source File: RedisCacheConfiguration.java From NetworkDisk_Storage with GNU General Public License v2.0 | 5 votes |
public JedisPool getRedisPoolFactory() { logger.info("JedisPool注入成功!!"); logger.info("redis地址:" + host + ":" + port); JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxIdle(maxIdle); jedisPoolConfig.setMaxWaitMillis(maxWaitMillis); JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password); return jedisPool; }
Example 11
Source File: JedisPoolUtil.java From withme3.0 with MIT License | 5 votes |
/** * 创建连接池并且配置相关的参数 */ private static void createJedisPool(){ JedisPoolConfig config = new JedisPoolConfig(); //设置最大连接数 config.setMaxTotal(CONSTANT.MAX_TOTAL); //设置最长等待时间(单位ms) config.setMaxWaitMillis(CONSTANT.MAX_WAIT); //设置空间链接 config.setMinIdle(CONSTANT.MAX_IDLE); //创建连接池 pool = new JedisPool(config, CONSTANT.REDIS_ADDRESS, CONSTANT.REDIS_PORT); }
Example 12
Source File: RedisPoolFactory.java From seckill with Apache License 2.0 | 5 votes |
@Bean public JedisPool JedisPoolFactory() { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxIdle(redisConfig.getPoolMaxIdle()); poolConfig.setMaxTotal(redisConfig.getPoolMaxTotal()); poolConfig.setMaxWaitMillis(redisConfig.getPoolMaxWait() * 1000); JedisPool jedisPool = new JedisPool(poolConfig, redisConfig.getHost(), redisConfig.getPort(), redisConfig.getTimeout() * 1000, redisConfig.getPassword(), 0); return jedisPool; }
Example 13
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 14
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 15
Source File: TestRedisDelayQueue.java From delay-queue with Apache License 2.0 | 5 votes |
@Before public void init() { String ip = "192.168.2.160"; Set<HostAndPort> nodes = new HashSet<>(); nodes.add(new HostAndPort(ip, 7701)); nodes.add(new HostAndPort(ip, 7702)); nodes.add(new HostAndPort(ip, 7703)); nodes.add(new HostAndPort(ip, 7704)); nodes.add(new HostAndPort(ip, 7705)); nodes.add(new HostAndPort(ip, 7706)); JedisPoolConfig pool = new JedisPoolConfig(); pool.setMaxTotal(100); pool.setFairness(false); pool.setNumTestsPerEvictionRun(100); pool.setMaxWaitMillis(5000); pool.setTestOnBorrow(true); jedisCluster = new JedisCluster(nodes, 1000, 1000, 100, null, pool); // maxAttempt必须调大 jedisCluster.set("test", "test"); queue = new RedisDelayQueue("com.meipian", "delayqueue", jedisCluster, 60 * 1000, new DelayQueueProcessListener() { @Override public void pushCallback(Message message) { } @Override public void peekCallback(Message message) { System.out.println("message----->" + message); queue.ack(message.getId());//确认操作。将会删除消息 } @Override public void ackCallback(Message message) { } }); }
Example 16
Source File: JedisConfig.java From springboot-learn with MIT License | 5 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) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(maxTotal); config.setMaxIdle(maxIdle); config.setMaxWaitMillis(maxWaitMillis); config.setTestOnBorrow(testOnBorrow); config.setTestOnReturn(testOnBorrow); return config; }
Example 17
Source File: RedisConfig.java From JavaQuarkBBS with Apache License 2.0 | 5 votes |
@Bean public JedisPool redisPoolFactory() { Logger.getLogger(getClass()).info("JedisPool注入成功!!"); Logger.getLogger(getClass()).info("redis地址:" + host + ":" + port); JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxIdle(maxIdle); jedisPoolConfig.setMaxWaitMillis(maxWaitMillis); JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout); return jedisPool; }
Example 18
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); }
Example 19
Source File: RedisConfig.java From ace-cache with Apache License 2.0 | 5 votes |
@Bean public JedisPoolConfig constructJedisPoolConfig() { JedisPoolConfig config = new JedisPoolConfig(); // 控制一个pool可分配多少个jedis实例,通过pool.getResource()来获取; // 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。 config.setMaxTotal(Integer.parseInt(maxActive)); // 控制一个pool最多有多少个状态为idle(空闲的)的jedis实例。 config.setMaxIdle(Integer.parseInt(maxIdle)); // 表示当borrow(引入)一个jedis实例时,最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException; config.setMaxWaitMillis(Integer.parseInt(maxWait)); config.setTestOnBorrow(true); return config; }
Example 20
Source File: MyTest.java From ehousechina with Apache License 2.0 | 4 votes |
@Test public void test1() { Snowflake s = SnowflakeUtil.getSnowflake(); JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(500); jedisPoolConfig.setMaxIdle(500); jedisPoolConfig.setMaxWaitMillis(-1); jedisPoolConfig.setTestOnBorrow(true); jedisPoolConfig.setTestOnReturn(true); JedisPool jedisPool = new JedisPool(jedisPoolConfig, "10.99.70.53", 32853); try { while (true) { i++; long id = s.next(); System.out.println(i + "----" + id); // pool.execute(new Runnable() { // @Override // public void run() { // i++; // Jedis jedis = jedisPool.getResource(); // long id = s.next(); // System.out.println(i+"----"+id); // long value = jedis.setnx(String.valueOf(id), ""); // if(value==0){ // System.out.println("1111111111111111111111"); // } // jedis.close(); } // }); // TimeUnit.NANOSECONDS.sleep(1); // } } catch (Exception e) { e.printStackTrace(); } finally { jedisPool.close(); } // long value = jedis.setnx("test", "test"); // System.out.println(value); /* * jedis.close(); jedisPool.close(); */ }