Search in sources :

Example 41 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project jedis by xetorthio.

the class JedisPoolTest method selectDatabaseOnActivation.

@Test
public void selectDatabaseOnActivation() {
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "foobared");
    Jedis jedis0 = pool.getResource();
    assertEquals(0, jedis0.getDB());
    jedis0.select(1);
    assertEquals(1, jedis0.getDB());
    jedis0.close();
    Jedis jedis1 = pool.getResource();
    assertTrue("Jedis instance was not reused", jedis1 == jedis0);
    assertEquals(0, jedis1.getDB());
    jedis1.close();
    pool.destroy();
    assertTrue(pool.isClosed());
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Test(org.junit.Test)

Example 42 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project disgear by yangbutao.

the class CacheOperation method read.

public Map<String, String> read(String host, int port, String key) throws Exception {
    // host = "10.1.1.26";
    if (jredisPoolMap == null) {
        jredisPoolMap = new ConcurrentHashMap<String, JedisPool>();
    }
    JedisPool pool = jredisPoolMap.get(host + ":" + port);
    if (pool == null) {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxActive(100);
        config.setMaxIdle(20);
        config.setMaxWait(1000l);
        pool = new JedisPool(host, port);
        jredisPoolMap.put(host + ":" + port, pool);
    }
    Jedis jedis = null;
    try {
        jedis = pool.getResource();
        Map<String, String> user = jedis.hgetAll(key);
        /*
			 * AtomicLong tmp = count.get(host); if (tmp == null) { tmp = new
			 * AtomicLong(0); } tmp.addAndGet(1); count.put(host, tmp);
			 */
        return user;
    // System.out.println("********************"+count.toString());
    } finally {
        pool.returnResource(jedis);
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Example 43 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project ignite by apache.

the class RedisProtocolSelfTest method beforeTestsStarted.

/** {@inheritDoc} */
@Override
protected void beforeTestsStarted() throws Exception {
    startGrids(gridCount());
    JedisPoolConfig jedisPoolCfg = new JedisPoolConfig();
    jedisPoolCfg.setMaxWaitMillis(10000);
    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);
}
Also used : JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Aggregations

JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)43 JedisPool (redis.clients.jedis.JedisPool)35 Test (org.junit.Test)30 Jedis (redis.clients.jedis.Jedis)28 HostAndPort (redis.clients.jedis.HostAndPort)6 JedisCluster (redis.clients.jedis.JedisCluster)6 LinkedHashSet (java.util.LinkedHashSet)4 HashSet (java.util.HashSet)3 URISyntaxException (java.net.URISyntaxException)2 RedisTicketRegistryProperties (org.apereo.cas.configuration.model.support.redis.RedisTicketRegistryProperties)2 Before (org.junit.Before)2 InvalidURIException (redis.clients.jedis.exceptions.InvalidURIException)2 JedisException (redis.clients.jedis.exceptions.JedisException)2 BeanWrapper (org.springframework.beans.BeanWrapper)1 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)1 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)1 JedisExhaustedPoolException (redis.clients.jedis.exceptions.JedisExhaustedPoolException)1