Java Code Examples for redis.clients.jedis.JedisPoolConfig#setTestOnCreate()

The following examples show how to use redis.clients.jedis.JedisPoolConfig#setTestOnCreate() . 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: RedisUtils.java    From nifi with Apache License 2.0 7 votes vote down vote up
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 2
Source File: JedisSampleMain.java    From pepper-metrics with Apache License 2.0 5 votes vote down vote up
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 3
Source File: Client.java    From JRedisBloom with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Create a new client to ReBloom
 * @param host the redis host
 * @param port the redis port
 * @param timeout connection timeout
 * @param poolSize the poolSize of JedisPool
 */
public Client(String host, int port, int timeout, int poolSize) {
  JedisPoolConfig conf = new JedisPoolConfig();
  conf.setMaxTotal(poolSize);
  conf.setTestOnBorrow(false);
  conf.setTestOnReturn(false);
  conf.setTestOnCreate(false);
  conf.setTestWhileIdle(false);
  conf.setMinEvictableIdleTimeMillis(60000);
  conf.setTimeBetweenEvictionRunsMillis(30000);
  conf.setNumTestsPerEvictionRun(-1);
  conf.setFairness(true);

  pool = new JedisPool(conf, host, port, timeout);
}
 
Example 4
Source File: RedisClusterConnPool.java    From yuzhouwan with Apache License 2.0 5 votes vote down vote up
private JedisPoolConfig buildConf() {
    // org.apache.commons.pool2.impl.BaseObjectPoolConfig
    JedisPoolConfig conf = new JedisPoolConfig();
    conf.setMaxTotal(1000);
    conf.setMinIdle(50);
    conf.setMaxIdle(100);
    // conf.setMaxWaitMillis(6 * 1000);
    conf.setTestOnCreate(true);
    conf.setTestOnBorrow(true);
    conf.setTestOnReturn(true);
    conf.setTestWhileIdle(true);
    // conf.setTimeBetweenEvictionRunsMillis(1);
    conf.setNumTestsPerEvictionRun(30);
    return conf;
}
 
Example 5
Source File: RedisSentinelJobStoreTest.java    From quartz-redis-jobstore with Apache License 2.0 3 votes vote down vote up
@Before
public void setUpRedis() throws IOException, SchedulerConfigException {
    final List<Integer> sentinels = Arrays.asList(getPort(), getPort());
    final List<Integer> group1 = Arrays.asList(getPort(), getPort());
    final List<Integer> group2 = Arrays.asList(getPort(), getPort());
    //creates a cluster with 3 sentinels, quorum size of 2 and 3 replication groups, each with one master and one slave
    redisCluster = RedisCluster.builder().sentinelPorts(sentinels).quorumSize(2)
        .serverPorts(group1).replicationGroup("master1", 1)
        .serverPorts(group2).replicationGroup("master2", 1)
        .ephemeralServers().replicationGroup("master3", 1)
        .build();
    redisCluster.start();


    Set<String> jedisSentinelHosts = JedisUtil.sentinelHosts(redisCluster);

    joinedHosts = Joiner.on(",").join(jedisSentinelHosts);

    final short database = 1;
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    jedisPoolConfig.setTestOnBorrow(true);
    jedisPoolConfig.setTestOnCreate(true);
    jedisPoolConfig.setTestOnReturn(true);
    jedisPoolConfig.setMaxWaitMillis(2000);
    jedisPoolConfig.setMaxTotal(20);
    jedisPool = new JedisSentinelPool("master1", jedisSentinelHosts, jedisPoolConfig);
    jobStore = new RedisJobStore();
    jobStore.setHost(joinedHosts);
    jobStore.setJedisPool(jedisSentinelPool);
    jobStore.setLockTimeout(2000);
    jobStore.setMasterGroupName("master1");
    jobStore.setRedisSentinel(true);
    jobStore.setInstanceId("testJobStore1");
    jobStore.setDatabase(database);
    mockScheduleSignaler = mock(SchedulerSignaler.class);
    jobStore.initialize(null, mockScheduleSignaler);
    schema = new RedisJobStoreSchema();

    jedis = jedisPool.getResource();
    jedis.flushDB();

}