Search in sources :

Example 81 with JedisPool

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

the class CacheOperation method read.

public Map<String, String> read(String host, int port, String key) throws Exception {
    // host = "10.1.1.26";
    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();
        Map<String, String> user = jedis.hgetAll(key);
        /*
			 * AtomicLong tmp = count.get(host); if (tmp == null) { tmp = new
			 * AtomicLong(0); } tmp.addAndGet(1); count.put(host, tmp);
			 */
        return user;
    // System.out.println("********************"+count.toString());
    } finally {
        pool.returnResource(jedis);
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Example 82 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, "BbbWebPub");
    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 83 with JedisPool

use of redis.clients.jedis.JedisPool in project ignite by apache.

the class RedisProtocolSelfTest method beforeTestsStarted.

/** {@inheritDoc} */
@Override
protected void beforeTestsStarted() throws Exception {
    startGrids(gridCount());
    JedisPoolConfig jedisPoolCfg = new JedisPoolConfig();
    jedisPoolCfg.setMaxWaitMillis(10000);
    jedisPoolCfg.setMaxIdle(100);
    jedisPoolCfg.setMinIdle(1);
    jedisPoolCfg.setNumTestsPerEvictionRun(10);
    jedisPoolCfg.setTestOnBorrow(true);
    jedisPoolCfg.setTestOnReturn(true);
    jedisPoolCfg.setTestWhileIdle(true);
    jedisPoolCfg.setTimeBetweenEvictionRunsMillis(30000);
    pool = new JedisPool(jedisPoolCfg, HOST, PORT, 10000);
}
Also used : JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Example 84 with JedisPool

use of redis.clients.jedis.JedisPool in project ignite by apache.

the class RedisCommonAbstractTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    startGrids(gridCount());
    JedisPoolConfig jedisPoolCfg = new JedisPoolConfig();
    jedisPoolCfg.setMaxWaitMillis(20000);
    jedisPoolCfg.setMaxIdle(100);
    jedisPoolCfg.setMinIdle(1);
    jedisPoolCfg.setNumTestsPerEvictionRun(10);
    jedisPoolCfg.setTestOnBorrow(true);
    jedisPoolCfg.setTestOnReturn(true);
    jedisPoolCfg.setTestWhileIdle(true);
    jedisPoolCfg.setTimeBetweenEvictionRunsMillis(30000);
    pool = new JedisPool(jedisPoolCfg, HOST, PORT, 10000);
}
Also used : JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Example 85 with JedisPool

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

the class RedisStandaloneProvider method create.

public void create() {
    LOG.debug("Starting RedisStandaloneProvider ...");
    try {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(1000);
        poolConfig.setMinIdle(2);
        HostAndPort hostAndPort = RedisClusterProvider.hosts(redisConfiguration.getServers()).iterator().next();
        pool = new JedisPool(poolConfig, hostAndPort.getHost(), hostAndPort.getPort());
        testConnection();
        LOG.debug("RedisStandaloneProvider started.");
    } catch (Exception e) {
        throw new IllegalStateException("Error starting RedisStandaloneProvider", e);
    }
}
Also used : HostAndPort(redis.clients.jedis.HostAndPort) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Aggregations

JedisPool (redis.clients.jedis.JedisPool)108 Jedis (redis.clients.jedis.Jedis)75 Test (org.junit.Test)47 JedisPoolConfig (redis.clients.jedis.JedisPoolConfig)40 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)17 HostAndPort (redis.clients.jedis.HostAndPort)6 URI (java.net.URI)5 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)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