Search in sources :

Example 36 with JedisPool

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

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 37 with JedisPool

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

the class JedisPoolTest method checkJedisIsReusedWhenReturned.

@Test
public void checkJedisIsReusedWhenReturned() {
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
    Jedis jedis = pool.getResource();
    jedis.auth("foobared");
    jedis.set("foo", "0");
    jedis.close();
    jedis = pool.getResource();
    jedis.auth("foobared");
    jedis.incr("foo");
    jedis.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 38 with JedisPool

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

the class CacheOperation method insert.

public void insert(String host, int port, String key, String mapKey, String mapValue) {
    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();
        jedis.hset(key, mapKey, mapValue);
    } finally {
        pool.returnResource(jedis);
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Example 39 with JedisPool

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

the class CacheOperation method insert.

public void insert(String host, int port, String key, Map<String, String> hash) {
    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();
        jedis.hmset(key, hash);
    } finally {
        pool.returnResource(jedis);
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Example 40 with JedisPool

use of redis.clients.jedis.JedisPool in project jetcache by alibaba.

the class RedisCacheTest method testSimplePool.

@Test
public void testSimplePool() throws Exception {
    GenericObjectPoolConfig pc = new GenericObjectPoolConfig();
    pc.setMinIdle(2);
    pc.setMaxIdle(10);
    pc.setMaxTotal(10);
    JedisPool pool = new JedisPool(pc, "localhost", 6379);
    testWithPool(pool);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisPool(redis.clients.jedis.JedisPool) RefreshCacheTest(com.alicp.jetcache.RefreshCacheTest) Test(org.junit.Test) LoadingCacheTest(com.alicp.jetcache.LoadingCacheTest) AbstractExternalCacheTest(com.alicp.jetcache.test.external.AbstractExternalCacheTest)

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