Search in sources :

Example 16 with JedisPool

use of redis.clients.jedis.JedisPool 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 17 with JedisPool

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

the class JedisPoolTest method startWithUrlString.

@Test
public void startWithUrlString() {
    Jedis j = new Jedis("localhost", 6380);
    j.auth("foobared");
    j.select(2);
    j.set("foo", "bar");
    JedisPool pool = new JedisPool("redis://:foobared@localhost:6380/2");
    Jedis jedis = pool.getResource();
    assertEquals("PONG", jedis.ping());
    assertEquals("bar", jedis.get("foo"));
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) Test(org.junit.Test)

Example 18 with JedisPool

use of redis.clients.jedis.JedisPool 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 19 with JedisPool

use of redis.clients.jedis.JedisPool 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)

Example 20 with JedisPool

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

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)

Aggregations

JedisPool (redis.clients.jedis.JedisPool)72 Test (org.junit.Test)47 Jedis (redis.clients.jedis.Jedis)46 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)35 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)16 URI (java.net.URI)5 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 HostAndPort (redis.clients.jedis.HostAndPort)5 JedisCluster (redis.clients.jedis.JedisCluster)5 RpcException (com.alibaba.dubbo.rpc.RpcException)4 URISyntaxException (java.net.URISyntaxException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 JedisException (redis.clients.jedis.exceptions.JedisException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 InvalidURIException (redis.clients.jedis.exceptions.InvalidURIException)3 ArrayList (java.util.ArrayList)2