Search in sources :

Example 56 with JedisPool

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

the class TestRedisDataSourcesProvider method testRedisSink.

@SuppressWarnings("unchecked")
@Test
public void testRedisSink() {
    ISqlTridentDataSource ds = DataSourcesRegistry.constructTridentDataSource(URI.create("redis://:foobared@localhost:6380/2"), null, null, TBL_PROPERTIES, FIELDS);
    Assert.assertNotNull(ds);
    ISqlTridentDataSource.SqlTridentConsumer consumer = ds.getConsumer();
    Assert.assertEquals(RedisState.Factory.class, consumer.getStateFactory().getClass());
    Assert.assertEquals(RedisStateUpdater.class, consumer.getStateUpdater().getClass());
    RedisState state = (RedisState) consumer.getStateFactory().makeState(Collections.emptyMap(), null, 0, 1);
    StateUpdater stateUpdater = consumer.getStateUpdater();
    JedisPool mockJedisPool = mock(JedisPool.class);
    Jedis mockJedis = mock(Jedis.class);
    Pipeline mockPipeline = mock(Pipeline.class);
    Whitebox.setInternalState(state, "jedisPool", mockJedisPool);
    when(mockJedisPool.getResource()).thenReturn(mockJedis);
    when(mockJedis.pipelined()).thenReturn(mockPipeline);
    List<TridentTuple> tupleList = mockTupleList();
    stateUpdater.updateState(state, tupleList, null);
    for (TridentTuple t : tupleList) {
        // PK goes to the key
        String id = String.valueOf(t.getValueByField("ID"));
        String serializedValue = new String(SERIALIZER.write(t.getValues(), null).array());
        verify(mockPipeline).hset(eq(ADDITIONAL_KEY), eq(id), eq(serializedValue));
    }
    verify(mockPipeline).sync();
    verify(mockJedis).close();
}
Also used : Jedis(redis.clients.jedis.Jedis) RedisState(org.apache.storm.redis.trident.state.RedisState) ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource) JedisPool(redis.clients.jedis.JedisPool) StateUpdater(org.apache.storm.trident.state.StateUpdater) RedisStateUpdater(org.apache.storm.redis.trident.state.RedisStateUpdater) RedisClusterStateUpdater(org.apache.storm.redis.trident.state.RedisClusterStateUpdater) Pipeline(redis.clients.jedis.Pipeline) TridentTuple(org.apache.storm.trident.tuple.TridentTuple) Test(org.junit.Test)

Example 57 with JedisPool

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

the class JedisConnection method dbConnect.

public static Jedis dbConnect() {
    String serverIP = "127.0.0.1";
    //String serverIP = getLocalIP();
    //serverIP = serverIP.substring(7);
    JedisPool redisPool = new JedisPool(serverIP, 6379);
    try {
        return redisPool.getResource();
    } catch (Exception e) {
    //log.error("Error in PollApplication.dbConnect():");
    ///log.error(e.toString());
    }
    //log.error("Returning NULL from dbConnect()");
    return null;
}
Also used : JedisPool(redis.clients.jedis.JedisPool) UnknownHostException(java.net.UnknownHostException)

Example 58 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 59 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 60 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)

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