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();
}
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));
}
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));
}
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());
}
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());
}
Aggregations