Search in sources :

Example 26 with ShardedJedisPool

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

the class ShardedJedisPoolTest method checkResourceIsCloseable.

@Test
public void checkResourceIsCloseable() throws URISyntaxException {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1);
    config.setBlockWhenExhausted(false);
    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
    shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6380")));
    shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6379")));
    ShardedJedisPool pool = new ShardedJedisPool(config, shards);
    ShardedJedis jedis = pool.getResource();
    try {
        jedis.set("hello", "jedis");
    } finally {
        jedis.close();
    }
    ShardedJedis jedis2 = pool.getResource();
    try {
        assertEquals(jedis, jedis2);
    } finally {
        jedis2.close();
    }
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedis(redis.clients.jedis.ShardedJedis) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) URI(java.net.URI) Test(org.junit.Test)

Example 27 with ShardedJedisPool

use of redis.clients.jedis.ShardedJedisPool in project oxCore by GluuFederation.

the class RedisShardedProvider method create.

public void create() {
    try {
        LOG.debug("Starting RedisShardedProvider ... configuration:" + redisConfiguration);
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(1000);
        poolConfig.setMinIdle(2);
        pool = new ShardedJedisPool(poolConfig, shards(redisConfiguration.getServers()));
        testConnection();
        LOG.debug("RedisShardedProvider started.");
    } catch (Exception e) {
        LOG.error("Failed to start RedisShardedProvider.");
        throw new IllegalStateException("Error starting RedisShardedProvider", e);
    }
}
Also used : ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Aggregations

ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)27 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)26 Test (org.junit.Test)26 ShardedJedis (redis.clients.jedis.ShardedJedis)26 JedisShardInfo (redis.clients.jedis.JedisShardInfo)10 ArrayList (java.util.ArrayList)8 URI (java.net.URI)6 Jedis (redis.clients.jedis.Jedis)6 ShardedJedisPipeline (redis.clients.jedis.ShardedJedisPipeline)2 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)1