Search in sources :

Example 26 with JedisPool

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

the class MessageSender method start.

public void start() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(32);
    config.setMaxIdle(8);
    config.setMinIdle(1);
    config.setTestOnBorrow(true);
    config.setTestOnReturn(true);
    config.setTestWhileIdle(true);
    config.setNumTestsPerEvictionRun(12);
    config.setMaxWaitMillis(5000);
    config.setTimeBetweenEvictionRunsMillis(60000);
    config.setBlockWhenExhausted(true);
    // Set the name of this client to be able to distinguish when doing
    // CLIENT LIST on redis-cli
    redisPool = new JedisPool(config, host, port, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, "BbbRed5AppsPub");
    log.info("Redis message publisher starting!");
    try {
        sendMessage = true;
        Runnable messageSender = new Runnable() {

            public void run() {
                while (sendMessage) {
                    try {
                        MessageToSend msg = messages.take();
                        publish(msg.getChannel(), msg.getMessage());
                    } catch (InterruptedException e) {
                        log.warn("Failed to get message from queue.");
                    }
                }
            }
        };
        msgSenderExec.execute(messageSender);
    } catch (Exception e) {
        log.error("Error subscribing to channels: " + e.getMessage());
    }
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisPool(redis.clients.jedis.JedisPool)

Example 27 with JedisPool

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

the class JedisClusterTest method testSetClientName.

@Test
public void testSetClientName() {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
    String clientName = "myAppName";
    JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", clientName, DEFAULT_CONFIG);
    Map<String, JedisPool> clusterNodes = jc.getClusterNodes();
    Collection<JedisPool> values = clusterNodes.values();
    for (JedisPool jedisPool : values) {
        Jedis jedis = jedisPool.getResource();
        try {
            assertEquals(clientName, jedis.clientGetname());
        } finally {
            jedis.close();
        }
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) Jedis(redis.clients.jedis.Jedis) JedisCluster(redis.clients.jedis.JedisCluster) JedisPool(redis.clients.jedis.JedisPool) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 28 with JedisPool

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

the class JedisClusterTest method testCloseable.

@Test
public void testCloseable() throws IOException {
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
    JedisCluster jc = null;
    try {
        jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
        jc.set("51", "foo");
    } finally {
        if (jc != null) {
            jc.close();
        }
    }
    Iterator<JedisPool> poolIterator = jc.getClusterNodes().values().iterator();
    while (poolIterator.hasNext()) {
        JedisPool pool = poolIterator.next();
        try {
            pool.getResource();
            fail("JedisCluster's internal pools should be already destroyed");
        } catch (JedisConnectionException e) {
        // ok to go...
        }
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) JedisPool(redis.clients.jedis.JedisPool) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 29 with JedisPool

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

the class JedisPoolTest method checkConnections.

@Test
public void checkConnections() {
    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.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 30 with JedisPool

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

the class JedisPoolTest method securePool.

@Test
public void securePool() {
    JedisPoolConfig config = new JedisPoolConfig();
    config.setTestOnBorrow(true);
    JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "foobared");
    Jedis jedis = pool.getResource();
    jedis.set("foo", "bar");
    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)

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