Java Code Examples for org.redisson.api.RBatch#execute()

The following examples show how to use org.redisson.api.RBatch#execute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CaseController.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/redisson-case")
@ResponseBody
public String redissonCase() {
    RBucket<String> bucket = client.getBucket("key_a");
    bucket.set("value_a");
    RBatch batch = client.createBatch();
    batch.getBucket("batch_k_a").setAsync("batch_v_a");
    batch.getBucket("batch_k_b").setAsync("batch_v_b");
    batch.getBucket("batch_k_b").expireAsync(20, TimeUnit.SECONDS);
    batch.execute();
    return "Success";
}
 
Example 2
Source File: RedissonKeysTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteByPatternBatch() {
    RBucket<String> bucket = redisson.getBucket("test0");
    bucket.set("someValue3");
    assertThat(bucket.isExists()).isTrue();

    RBucket<String> bucket2 = redisson.getBucket("test9");
    bucket2.set("someValue4");
    assertThat(bucket.isExists()).isTrue();

    RMap<String, String> map = redisson.getMap("test2");
    map.fastPut("1", "2");
    assertThat(map.isExists()).isTrue();

    RMap<String, String> map2 = redisson.getMap("test3");
    map2.fastPut("1", "5");
    assertThat(map2.isExists()).isTrue();


    RBatch batch = redisson.createBatch();
    batch.getKeys().deleteByPatternAsync("test?");
    BatchResult<?> r = batch.execute();
    Assert.assertEquals(4L, r.getResponses().get(0));
}
 
Example 3
Source File: RedissonInstrumentationTest.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Test
void testBatch() {
    try (Scope scope = tracer.startRootTransaction(getClass().getClassLoader()).withName("transaction").activateInScope()) {
        RBatch batch = redisson.createBatch();
        batch.getBucket("batch1").setAsync("v1");
        batch.getBucket("batch2").setAsync("v2");
        batch.execute();

        assertThat(redisson.getBucket("batch1").get()).isEqualTo("v1");
        assertThat(redisson.getBucket("batch2").get()).isEqualTo("v2");
    }

    assertTransactionWithRedisSpans("SET... [bulk]", "GET", "GET");
}
 
Example 4
Source File: RedissonSessionRepository.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public String changeSessionId() {
    String oldId = delegate.getId();
    String id = delegate.changeSessionId();

    RBatch batch = redisson.createBatch(BatchOptions.defaults());
    batch.getBucket(getExpiredKey(oldId)).remainTimeToLiveAsync();
    batch.getBucket(getExpiredKey(oldId)).deleteAsync();
    batch.getMap(map.getName(), map.getCodec()).readAllMapAsync();
    batch.getMap(map.getName()).deleteAsync();

    BatchResult<?> res = batch.execute();
    List<?> list = res.getResponses();

    Long remainTTL = (Long) list.get(0);
    Map<String, Object> oldState = (Map<String, Object>) list.get(2);

    if (remainTTL == -2) {
        // Either:
        // - a parallel request also invoked changeSessionId() on this session, and the
        //   expiredKey for oldId had been deleted
        // - sessions do not expire
        remainTTL = delegate.getMaxInactiveInterval().toMillis();
    }

    RBatch batchNew = redisson.createBatch();
    batchNew.getMap(keyPrefix + id, map.getCodec()).putAllAsync(oldState);
    if (remainTTL > 0) {
        batchNew.getBucket(getExpiredKey(id)).setAsync("", remainTTL, TimeUnit.MILLISECONDS);
    }
    batchNew.execute();

    map = redisson.getMap(keyPrefix + id, map.getCodec());

    return id;
}