Search in sources :

Example 6 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project cachecloud by sohutv.

the class JedisPoolTest method getNumActiveReturnsTheCorrectNumber.

@Test
public void getNumActiveReturnsTheCorrectNumber() {
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
    Jedis jedis = pool.getResource();
    jedis.auth("foobared");
    jedis.set("foo", "bar");
    assertEquals("bar", jedis.get("foo"));
    assertEquals(1, pool.getNumActive());
    Jedis jedis2 = pool.getResource();
    jedis.auth("foobared");
    jedis.set("foo", "bar");
    assertEquals(2, pool.getNumActive());
    jedis.close();
    assertEquals(1, pool.getNumActive());
    jedis2.close();
    assertEquals(0, pool.getNumActive());
    pool.destroy();
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Test(org.junit.Test)

Example 7 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project cachecloud by sohutv.

the class JedisPoolTest method checkCloseableConnections.

@Test
public void checkCloseableConnections() throws Exception {
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
    Jedis jedis = pool.getResource();
    jedis.auth("foobared");
    jedis.set("foo", "bar");
    assertEquals("bar", jedis.get("foo"));
    jedis.close();
    pool.close();
    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 8 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project cachecloud by sohutv.

the class JedisPoolTest method nonDefaultDatabase.

@Test
public void nonDefaultDatabase() {
    JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "foobared");
    Jedis jedis0 = pool0.getResource();
    jedis0.set("foo", "bar");
    assertEquals("bar", jedis0.get("foo"));
    jedis0.close();
    pool0.destroy();
    assertTrue(pool0.isClosed());
    JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "foobared", 1);
    Jedis jedis1 = pool1.getResource();
    assertNull(jedis1.get("foo"));
    jedis1.close();
    pool1.destroy();
    assertTrue(pool1.isClosed());
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Test(org.junit.Test)

Example 9 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project cachecloud by sohutv.

the class JedisPoolTest method customClientName.

@Test
public void customClientName() {
    JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name");
    Jedis jedis = pool0.getResource();
    assertEquals("my_shiny_client_name", jedis.clientGetname());
    jedis.close();
    pool0.destroy();
    assertTrue(pool0.isClosed());
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Test(org.junit.Test)

Example 10 with JedisPoolConfig

use of redis.clients.jedis.JedisPoolConfig in project cachecloud by sohutv.

the class JedisPoolTest method testAddObject.

@Test
public void testAddObject() {
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
    pool.addObjects(1);
    assertEquals(pool.getNumIdle(), 1);
    pool.destroy();
}
Also used : JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Test(org.junit.Test)

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