Search in sources :

Example 1 with Pipeline

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

the class HashesCommandsTest method hgetAllPipeline.

@Test
public void hgetAllPipeline() {
    Map<byte[], byte[]> bh = new HashMap<byte[], byte[]>();
    bh.put(bbar, bcar);
    bh.put(bcar, bbar);
    jedis.hmset(bfoo, bh);
    Pipeline pipeline = jedis.pipelined();
    Response<Map<byte[], byte[]>> bhashResponse = pipeline.hgetAll(bfoo);
    pipeline.sync();
    Map<byte[], byte[]> bhash = bhashResponse.get();
    assertEquals(2, bhash.size());
    assertArrayEquals(bcar, bhash.get(bbar));
    assertArrayEquals(bbar, bhash.get(bcar));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 2 with Pipeline

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

the class PipelinedGetSetBenchmark method main.

public static void main(String[] args) throws UnknownHostException, IOException {
    Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
    jedis.connect();
    jedis.auth("foobared");
    jedis.flushAll();
    long begin = Calendar.getInstance().getTimeInMillis();
    Pipeline p = jedis.pipelined();
    for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
        String key = "foo" + n;
        p.set(key, "bar" + n);
        p.get(key);
    }
    p.sync();
    long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
    jedis.disconnect();
    System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
Also used : Jedis(redis.clients.jedis.Jedis) Pipeline(redis.clients.jedis.Pipeline)

Example 3 with Pipeline

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

the class PipeliningTest method testEval.

@Test
public void testEval() {
    String script = "return 'success!'";
    Pipeline p = jedis.pipelined();
    Response<Object> result = p.eval(script);
    p.sync();
    assertEquals("success!", result.get());
}
Also used : Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 4 with Pipeline

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

the class PipeliningTest method testPipelinedTransactionResponse.

@Test
public void testPipelinedTransactionResponse() {
    String key1 = "key1";
    String val1 = "val1";
    String key2 = "key2";
    String val2 = "val2";
    String key3 = "key3";
    String field1 = "field1";
    String field2 = "field2";
    String field3 = "field3";
    String field4 = "field4";
    String value1 = "value1";
    String value2 = "value2";
    String value3 = "value3";
    String value4 = "value4";
    Map<String, String> hashMap = new HashMap<String, String>();
    hashMap.put(field1, value1);
    hashMap.put(field2, value2);
    String key4 = "key4";
    Map<String, String> hashMap1 = new HashMap<String, String>();
    hashMap1.put(field3, value3);
    hashMap1.put(field4, value4);
    jedis.set(key1, val1);
    jedis.set(key2, val2);
    jedis.hmset(key3, hashMap);
    jedis.hmset(key4, hashMap1);
    Pipeline pipeline = jedis.pipelined();
    pipeline.multi();
    pipeline.get(key1);
    pipeline.hgetAll(key2);
    pipeline.hgetAll(key3);
    pipeline.get(key4);
    Response<List<Object>> response = pipeline.exec();
    pipeline.sync();
    List<Object> result = response.get();
    assertEquals(4, result.size());
    assertEquals("val1", result.get(0));
    assertTrue(result.get(1) instanceof JedisDataException);
    Map<String, String> hashMapReceived = (Map<String, String>) result.get(2);
    Iterator<String> iterator = hashMapReceived.keySet().iterator();
    String mapKey1 = iterator.next();
    String mapKey2 = iterator.next();
    assertFalse(iterator.hasNext());
    verifyHasBothValues(mapKey1, mapKey2, field1, field2);
    String mapValue1 = hashMapReceived.get(mapKey1);
    String mapValue2 = hashMapReceived.get(mapKey2);
    verifyHasBothValues(mapValue1, mapValue2, value1, value2);
    assertTrue(result.get(3) instanceof JedisDataException);
}
Also used : JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 5 with Pipeline

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

the class PipeliningTest method pipelineDiscardShoudThrowJedisDataExceptionWhenNotInMulti.

@Test(expected = JedisDataException.class)
public void pipelineDiscardShoudThrowJedisDataExceptionWhenNotInMulti() {
    Pipeline pipeline = jedis.pipelined();
    pipeline.discard();
}
Also used : Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Aggregations

Pipeline (redis.clients.jedis.Pipeline)77 Test (org.junit.Test)72 Jedis (redis.clients.jedis.Jedis)12 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)6 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)6 HashMap (java.util.HashMap)5 Set (java.util.Set)3 Response (redis.clients.jedis.Response)3 LinkedHashMap (java.util.LinkedHashMap)2 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)1 BasePinpointTest (com.navercorp.pinpoint.test.junit4.BasePinpointTest)1 RedisDataTypeDescription (org.apache.storm.redis.common.mapper.RedisDataTypeDescription)1 RedisClusterStateUpdater (org.apache.storm.redis.trident.state.RedisClusterStateUpdater)1 RedisState (org.apache.storm.redis.trident.state.RedisState)1 RedisStateUpdater (org.apache.storm.redis.trident.state.RedisStateUpdater)1 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)1 StateUpdater (org.apache.storm.trident.state.StateUpdater)1 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)1