@Test(expected = JedisDataException.class) public void pipelineMultiShoudThrowJedisDataExceptionWhenAlreadyInMulti() { Pipeline pipeline = jedis.pipelined(); pipeline.multi(); pipeline.set("foo", "3"); pipeline.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)); }
@Test public void testDiscardInPipeline() { Pipeline pipeline = jedis.pipelined(); pipeline.multi(); pipeline.set("foo", "bar"); Response<String> discard = pipeline.discard(); Response<String> get = pipeline.get("foo"); pipeline.sync(); discard.get(); get.get(); }
public void pipelineWithTransaction() { Jedis jedis = pool.getResource(); try { Pipeline p = jedis.pipelined(); p.multi(); for (int i = 0; i < rowCount; i++) { String key = RandomStringUtils.randomAlphabetic(8); p.set(key, RandomStringUtils.randomNumeric(5)); p.expire(key, 5 * 60); } p.exec(); p.sync(); } catch (Exception e) { pool.returnResource(jedis); } }
@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()); }