Ejemplo n.º 1
0
  @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));
  }
Ejemplo n.º 2
0
  @Test
  public void pipeline() throws UnsupportedEncodingException {
    Pipeline p = jedis.pipelined();
    p.set("foo", "bar");
    p.get("foo");
    List<Object> results = p.syncAndReturnAll();

    assertEquals(2, results.size());
    assertEquals("OK", results.get(0));
    assertEquals("bar", results.get(1));
  }
Ejemplo n.º 3
0
 /** Execute with a call back action with result in pipeline. */
 public List<Object> execute(PipelineAction pipelineAction) throws JedisException {
   Jedis jedis = null;
   boolean broken = false;
   try {
     jedis = jedisPool.getResource();
     Pipeline pipeline = jedis.pipelined();
     pipelineAction.action(pipeline);
     return pipeline.syncAndReturnAll();
   } catch (JedisException e) {
     broken = handleJedisException(e);
     throw e;
   } finally {
     closeResource(jedis, broken);
   }
 }