Search in sources :

Example 46 with JedisPool

use of redis.clients.jedis.JedisPool in project twitter-2-weibo by rjyo.

the class CommandServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    log.info("Web started.");
    JedisPool pool = getPool(getServletContext());
    DBHelper helper = DBHelperFactory.createHelper(pool);
    // clear the queue
    helper.clearQueue();
    Scheduler scheduler = new Scheduler();
    QueueTask task = new QueueTask();
    task.setHelper(DBHelperFactory.createHelper(pool));
    scheduler.schedule("*/2 * * * *", task);
    scheduler.start();
    log.info("Cron scheduler started.");
    log.info("Worker started.");
    // 1 Threads to handle the sync job
    new Thread(new SyncWorkerRunnable(DBHelperFactory.createHelper(pool))).start();
}
Also used : DBHelper(h2weibo.model.DBHelper) Scheduler(it.sauronsoftware.cron4j.Scheduler) JedisPool(redis.clients.jedis.JedisPool)

Example 47 with JedisPool

use of redis.clients.jedis.JedisPool in project twitter-2-weibo by rjyo.

the class WorkerServlet method init.

@Override
public void init(final ServletConfig config) throws ServletException {
    super.init(config);
    log.info("Worker started.");
    JedisPool pool = getPool(getServletContext());
    // 3 Threads to handle the sync job
    new Thread(new SyncWorkerRunnable(DBHelperFactory.createHelper(pool))).start();
}
Also used : JedisPool(redis.clients.jedis.JedisPool)

Example 48 with JedisPool

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

the class RedisSinkBolt method prepare.

@Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
    this.collector = collector;
    GenericObjectPoolConfig pconf = new GenericObjectPoolConfig();
    pconf.setMaxWaitMillis(2000);
    pconf.setMaxTotal(1000);
    pconf.setTestOnBorrow(false);
    pconf.setTestOnReturn(false);
    pconf.setTestWhileIdle(true);
    pconf.setMinEvictableIdleTimeMillis(120000);
    pconf.setTimeBetweenEvictionRunsMillis(60000);
    pconf.setNumTestsPerEvictionRun(-1);
    pool = new JedisPool(pconf, redisHost, redisPort, timeout);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisPool(redis.clients.jedis.JedisPool)

Example 49 with JedisPool

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

the class RedisRegistry method doUnregister.

@Override
public void doUnregister(URL url) {
    String key = toCategoryPath(url);
    String value = url.toFullString();
    RpcException exception = null;
    boolean success = false;
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        try {
            Jedis jedis = jedisPool.getResource();
            try {
                jedis.hdel(key, value);
                jedis.publish(key, Constants.UNREGISTER);
                success = true;
                if (!replicate) {
                    //  如果服务器端已同步数据,只需写入单台机器
                    break;
                }
            } finally {
                jedisPool.returnResource(jedis);
            }
        } catch (Throwable t) {
            exception = new RpcException("Failed to unregister service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
        }
    }
    if (exception != null) {
        if (success) {
            logger.warn(exception.getMessage(), exception);
        } else {
            throw exception;
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) RpcException(com.alibaba.dubbo.rpc.RpcException) JedisPool(redis.clients.jedis.JedisPool) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 50 with JedisPool

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

the class JedisPoolTest method testCloseConnectionOnMakeObject.

@Test
public void testCloseConnectionOnMakeObject() {
    JedisPoolConfig config = new JedisPoolConfig();
    config.setTestOnBorrow(true);
    JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "wrong pass");
    Jedis jedis = new Jedis("redis://:foobared@localhost:6379/");
    int currentClientCount = getClientCount(jedis.clientList());
    try {
        pool.getResource();
        fail("Should throw exception as password is incorrect.");
    } catch (Exception e) {
        assertEquals(currentClientCount, getClientCount(jedis.clientList()));
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) JedisPool(redis.clients.jedis.JedisPool) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) URISyntaxException(java.net.URISyntaxException) JedisException(redis.clients.jedis.exceptions.JedisException) InvalidURIException(redis.clients.jedis.exceptions.InvalidURIException) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) 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