Search in sources :

Example 1 with Response

use of redis.clients.jedis.Response in project cachecloud by sohutv.

the class TransactionCommandsTest method execGetResponse.

@Test
public void execGetResponse() {
    Transaction t = jedis.multi();
    t.set("foo", "bar");
    t.smembers("foo");
    t.get("foo");
    List<Response<?>> lr = t.execGetResponse();
    try {
        lr.get(1).get();
        fail("We expect exception here!");
    } catch (JedisDataException e) {
    // that is fine we should be here
    }
    assertEquals("bar", lr.get(2).get());
}
Also used : Response(redis.clients.jedis.Response) Transaction(redis.clients.jedis.Transaction) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Test(org.junit.Test)

Example 2 with Response

use of redis.clients.jedis.Response in project cachecloud by sohutv.

the class PipeliningTest method multiWithMassiveRequests.

@Test
public void multiWithMassiveRequests() {
    Pipeline p = jedis.pipelined();
    p.multi();
    List<Response<?>> responseList = new ArrayList<Response<?>>();
    for (int i = 0; i < 100000; i++) {
        // any operation should be ok, but shouldn't forget about timeout
        responseList.add(p.setbit("test", 1, true));
    }
    Response<List<Object>> exec = p.exec();
    p.sync();
    // we don't need to check return value
    // if below codes run without throwing Exception, we're ok
    exec.get();
    for (Response<?> resp : responseList) {
        resp.get();
    }
}
Also used : Response(redis.clients.jedis.Response) Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 3 with Response

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

the class PipeliningTest method multiWithMassiveRequests.

@Test
public void multiWithMassiveRequests() {
    Pipeline p = jedis.pipelined();
    p.multi();
    List<Response<?>> responseList = new ArrayList<Response<?>>();
    for (int i = 0; i < 100000; i++) {
        // any operation should be ok, but shouldn't forget about timeout
        responseList.add(p.setbit("test", 1, true));
    }
    Response<List<Object>> exec = p.exec();
    p.sync();
    // we don't need to check return value
    // if below codes run without throwing Exception, we're ok
    exec.get();
    for (Response<?> resp : responseList) {
        resp.get();
    }
}
Also used : Response(redis.clients.jedis.Response) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Pipeline(redis.clients.jedis.Pipeline) Test(org.junit.Test)

Example 4 with Response

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

the class TransactionCommandsTest method execGetResponse.

@Test
public void execGetResponse() {
    Transaction t = jedis.multi();
    t.set("foo", "bar");
    t.smembers("foo");
    t.get("foo");
    List<Response<?>> lr = t.execGetResponse();
    try {
        lr.get(1).get();
        fail("We expect exception here!");
    } catch (JedisDataException e) {
    // that is fine we should be here
    }
    assertEquals("bar", lr.get(2).get());
}
Also used : Response(redis.clients.jedis.Response) Transaction(redis.clients.jedis.Transaction) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Test(org.junit.Test)

Example 5 with Response

use of redis.clients.jedis.Response in project jetcache by alibaba.

the class RedisCache method do_PUT_ALL.

@Override
protected CacheResult do_PUT_ALL(Map<? extends K, ? extends V> map, long expireAfterWrite, TimeUnit timeUnit) {
    if (map == null) {
        return CacheResult.FAIL_ILLEGAL_ARGUMENT;
    }
    try (Jedis jedis = pool.getResource()) {
        int failCount = 0;
        List<Response<String>> responses = new ArrayList<>();
        Pipeline p = jedis.pipelined();
        for (Map.Entry<? extends K, ? extends V> en : map.entrySet()) {
            CacheValueHolder<V> holder = new CacheValueHolder(en.getValue(), timeUnit.toMillis(expireAfterWrite));
            Response<String> resp = p.psetex(buildKey(en.getKey()), timeUnit.toMillis(expireAfterWrite), valueEncoder.apply(holder));
            responses.add(resp);
        }
        p.sync();
        for (Response<String> resp : responses) {
            if (!"OK".equals(resp.get())) {
                failCount++;
            }
        }
        return failCount == 0 ? CacheResult.SUCCESS_WITHOUT_MSG : failCount == map.size() ? CacheResult.FAIL_WITHOUT_MSG : CacheResult.PART_SUCCESS_WITHOUT_MSG;
    } catch (Exception ex) {
        logError("PUT_ALL", "map(" + map.size() + ")", ex);
        return new CacheResult(ex);
    }
}
Also used : JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Pipeline(redis.clients.jedis.Pipeline) Response(redis.clients.jedis.Response) Jedis(redis.clients.jedis.Jedis)

Aggregations

Response (redis.clients.jedis.Response)5 Test (org.junit.Test)4 Pipeline (redis.clients.jedis.Pipeline)3 Transaction (redis.clients.jedis.Transaction)2 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Jedis (redis.clients.jedis.Jedis)1 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)1