Search in sources :

Example 71 with Pipeline

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

the class PipeliningTest method pipelineResponseWithinPipeline.

@Test(expected = JedisDataException.class)
public void pipelineResponseWithinPipeline() {
    jedis.set("string", "foo");
    Pipeline p = jedis.pipelined();
    Response<String> string = p.get("string");
    string.get();
    p.sync();
}
Also used : Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 72 with Pipeline

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

the class PipeliningTest method multi.

@Test
public void multi() {
    Pipeline p = jedis.pipelined();
    p.multi();
    Response<Long> r1 = p.hincrBy("a", "f1", -1);
    Response<Long> r2 = p.hincrBy("a", "f1", -2);
    Response<List<Object>> r3 = p.exec();
    List<Object> result = p.syncAndReturnAll();
    assertEquals(new Long(-1), r1.get());
    assertEquals(new Long(-3), r2.get());
    assertEquals(4, result.size());
    assertEquals("OK", result.get(0));
    assertEquals("QUEUED", result.get(1));
    assertEquals("QUEUED", result.get(2));
    // 4th result is a list with the results from the multi
    @SuppressWarnings("unchecked") List<Object> multiResult = (List<Object>) result.get(3);
    assertEquals(new Long(-1), multiResult.get(0));
    assertEquals(new Long(-3), multiResult.get(1));
    assertEquals(new Long(-1), r3.get().get(0));
    assertEquals(new Long(-3), r3.get().get(1));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 73 with Pipeline

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

the class PipeliningTest method testEvalNestedListsWithBinary.

@Test
public void testEvalNestedListsWithBinary() {
    byte[] bScript = SafeEncoder.encode("return { {KEYS[1]} , {2} }");
    byte[] bKey = SafeEncoder.encode("key1");
    Pipeline p = jedis.pipelined();
    Response<Object> result = p.eval(bScript, 1, bKey);
    p.sync();
    List<?> results = (List<?>) result.get();
    assertThat((List<byte[]>) results.get(0), listWithItem(bKey));
    assertThat((List<Long>) results.get(1), listWithItem(2L));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 74 with Pipeline

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

the class PipeliningTest method testEvalshaKeyAndArg.

@Test
public void testEvalshaKeyAndArg() {
    String key = "test";
    String arg = "3";
    String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";
    String sha1 = jedis.scriptLoad(script);
    assertTrue(jedis.scriptExists(sha1));
    Pipeline p = jedis.pipelined();
    p.set(key, "0");
    Response<Object> result0 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg));
    p.incr(key);
    Response<Object> result1 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg));
    Response<String> result2 = p.get(key);
    p.sync();
    assertNull(result0.get());
    assertNull(result1.get());
    assertEquals("13", result2.get());
}
Also used : Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 75 with Pipeline

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

the class PipeliningTest method multiWithSync.

@Test
public void multiWithSync() {
    jedis.set("foo", "314");
    jedis.set("bar", "foo");
    jedis.set("hello", "world");
    Pipeline p = jedis.pipelined();
    Response<String> r1 = p.get("bar");
    p.multi();
    Response<String> r2 = p.get("foo");
    p.exec();
    Response<String> r3 = p.get("hello");
    p.sync();
    // before multi
    assertEquals("foo", r1.get());
    // It should be readable whether exec's response was built or not
    assertEquals("314", r2.get());
    // after multi
    assertEquals("world", r3.get());
}
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