org.redisson.api.RBatch Java Examples

The following examples show how to use org.redisson.api.RBatch. 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: RedissonReferenceReactiveTest.java    From redisson with Apache License 2.0 8 votes vote down vote up
@Test
public void testReactiveToNormal() throws InterruptedException {
    RBatchReactive batch = redisson.createBatch(BatchOptions.defaults());
    RBucketReactive<Object> b1 = batch.getBucket("b1");
    RBucketReactive<Object> b2 = batch.getBucket("b2");
    RBucketReactive<Object> b3 = batch.getBucket("b3");
    b2.set(b3);
    b1.set(b2);
    b3.set(b1);
    sync(batch.execute());

    RedissonClient lredisson = Redisson.create(redisson.getConfig());
    RBatch b = lredisson.createBatch(BatchOptions.defaults());
    b.getBucket("b1").getAsync();
    b.getBucket("b2").getAsync();
    b.getBucket("b3").getAsync();
    List<RBucket> result = (List<RBucket>)b.execute().getResponses();
    assertEquals("b2", result.get(0).getName());
    assertEquals("b3", result.get(1).getName());
    assertEquals("b1", result.get(2).getName());

    lredisson.shutdown();
}
 
Example #2
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 #3
Source File: MapReduceExecutor.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public RFuture<Map<KOut, VOut>> executeAsync() {
    final RPromise<Map<KOut, VOut>> promise = new RedissonPromise<Map<KOut, VOut>>();
    final RFuture<Void> future = executeMapperAsync(resultMapName, null);
    addCancelHandling(promise, future);
    future.onComplete((res, e) -> {
        if (e != null) {
            promise.tryFailure(e);
            return;
        }
        
        RBatch batch = redisson.createBatch();
        RMapAsync<KOut, VOut> resultMap = batch.getMap(resultMapName, objectCodec);
        resultMap.readAllMapAsync().onComplete(new TransferListener<Map<KOut, VOut>>(promise));
        resultMap.deleteAsync();
        batch.executeAsync();
    });        
    return promise;
}
 
Example #4
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 #5
Source File: AbstractRedisSetWrapper.java    From geowave with Apache License 2.0 6 votes vote down vote up
public void flush() {
  batchCmdCounter = 0;
  final RBatch flushBatch = this.currentBatch;
  currentAsync = null;
  currentBatch = null;
  if (flushBatch == null) {
    return;
  }
  try {
    writeSemaphore.acquire();
    flushBatch.executeAsync().handle((r, t) -> {
      writeSemaphore.release();
      if ((t != null) && !(t instanceof CancellationException)) {
        LOGGER.error("Exception in batched write", t);
      }
      return r;
    });
  } catch (final InterruptedException e) {
    LOGGER.warn("async batch write semaphore interrupted", e);
    writeSemaphore.release();
  }
}
 
Example #6
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 #7
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;
}
 
Example #8
Source File: RedisScoredSetWrapper.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
protected RScoredSortedSetAsync<V> initAsyncCollection(
    final RBatch batch,
    final String setName,
    final Codec codec) {
  return batch.getScoredSortedSet(setName, codec);
}
 
Example #9
Source File: RedisMapWrapper.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
protected RMapAsync<byte[], byte[]> initAsyncCollection(
    final RBatch batch,
    final String setName,
    final Codec codec) {
  return batch.getMap(setName, codec);
}
 
Example #10
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RBatch createBatch(BatchOptions options) {
  return redissonClient.createBatch(options);
}
 
Example #11
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
@Deprecated
public RBatch createBatch() {
  return redissonClient.createBatch();
}
 
Example #12
Source File: AbstractRedisSetWrapper.java    From geowave with Apache License 2.0 votes vote down vote up
abstract protected A initAsyncCollection(RBatch batch, String setName, Codec codec);