Search in sources :

Example 16 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException 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 17 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project cachecloud by sohutv.

the class PipeliningTest method piplineWithError.

@Test
public void piplineWithError() {
    Pipeline p = jedis.pipelined();
    p.set("foo", "bar");
    Response<Set<String>> error = p.smembers("foo");
    Response<String> r = p.get("foo");
    p.sync();
    try {
        error.get();
        fail();
    } catch (JedisDataException e) {
    // that is fine we should be here
    }
    assertEquals(r.get(), "bar");
}
Also used : JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 18 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project cachecloud by sohutv.

the class Pipeline method multi.

public Response<String> multi() {
    if (currentMulti != null)
        throw new JedisDataException("MULTI calls can not be nested");
    client.multi();
    // Expecting
    Response<String> response = getResponse(BuilderFactory.STRING);
    // OK
    currentMulti = new MultiResponseBuilder();
    return response;
}
Also used : JedisDataException(redis.clients.jedis.exceptions.JedisDataException)

Example 19 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project cachecloud by sohutv.

the class Pipeline method exec.

public Response<List<Object>> exec() {
    if (currentMulti == null)
        throw new JedisDataException("EXEC without MULTI");
    client.exec();
    Response<List<Object>> response = super.getResponse(currentMulti);
    currentMulti.setResponseDependency(response);
    currentMulti = null;
    return response;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) JedisDataException(redis.clients.jedis.exceptions.JedisDataException)

Example 20 with JedisDataException

use of redis.clients.jedis.exceptions.JedisDataException in project cachecloud by sohutv.

the class Pipeline method discard.

public Response<String> discard() {
    if (currentMulti == null)
        throw new JedisDataException("DISCARD without MULTI");
    client.discard();
    currentMulti = null;
    return getResponse(BuilderFactory.STRING);
}
Also used : JedisDataException(redis.clients.jedis.exceptions.JedisDataException)

Aggregations

JedisDataException (redis.clients.jedis.exceptions.JedisDataException)46 Jedis (redis.clients.jedis.Jedis)27 Test (org.junit.Test)20 Pipeline (redis.clients.jedis.Pipeline)6 Transaction (redis.clients.jedis.Transaction)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)4 List (java.util.List)3 Set (java.util.Set)3 Logger (org.apache.log4j.Logger)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Response (redis.clients.jedis.Response)2 QueryRedisClusterDetailResponse (beans.response.QueryRedisClusterDetailResponse)1 ObjectInput (com.alibaba.dubbo.common.serialize.ObjectInput)1 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)1 Invocation (com.alibaba.dubbo.rpc.Invocation)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1