Redisson instances are fully thread-safe. Objects with synchronous/asynchronous methods could be reached via RedissonClient interface.
Reactive and RxJava3 methods through RedissonReactiveClient and RedissonRxClient interfaces respectively.

Redisson implements auto-retry policy per operation. Retry policy is controlled by retryAttempts and retryInterval settings. These settings are applied to each Redisson object. timeout setting is applied when the Redis command was successfully sent.

Settings above can be overridden per Redisson object instance. These settings apply to each method of a given Redisson object instance.

Here is an example with RBucket object:

  1. RedissonClient client = Redisson.create(config);
  2. RBucket<MyObject> bucket = client.getBucket('myObject');
  3. // sync way
  4. bucket.get();
  5. // async way
  6. RFuture<MyObject> result = bucket.getAsync();
  7. // instance with overridden retryInterval and timeout parameters
  8. RBucket<MyObject> bucket = client.getBucket(PlainOptions.name('myObject')
  9. .timeout(Duration.ofSeconds(3))
  10. .retryInterval(Duration.ofSeconds(5)));

3.1. Async way

Most Redisson objects extend asynchronous interface with asynchronous methods which mirror to synchronous methods. Like this:

  1. // RAtomicLong extends RAtomicLongAsync
  2. RAtomicLongAsync longObject = client.getAtomicLong("myLong");
  3. RFuture<Boolean> future = longObject.compareAndSetAsync(1, 401);

Asynchronous methods return RFuture object which extends CompletionStage interface.

  1. future.whenComplete((res, exception) -> {
  2. // handle both result and exception
  3. });
  4. // or
  5. future.thenAccept(res -> {
  6. // handle result
  7. }).exceptionally(exception -> {
  8. // handle exception
  9. });

Avoid to use blocking methods in future listeners. Listeners executed by netty-threads and delays in listeners may cause errors in Redis request/response processing. Use follow methods to execute blocking methods in listeners:

  1. future.whenCompleteAsync((res, exception) -> {
  2. // handle both result and exception
  3. }, executor);
  4. // or
  5. future.thenAcceptAsync(res -> {
  6. // handle result
  7. }, executor).exceptionallyAsync(exception -> {
  8. // handle exception
  9. }, executor);

3.2. Reactive way

Redisson exposes Reactive Streams API for most objects and based on two implementations:

  1. Project Reactor based implementation. Code example: ```java RedissonReactiveClient client = redissonClient.reactive();

RAtomicLongReactive atomicLong = client.getAtomicLong(“myLong”); Mono cs = longObject.compareAndSet(10, 91); Mono get = longObject.get();

get.doOnSuccess(res -> { // … }).subscribe();

  1. 2. [RxJava3](https://github.com/ReactiveX/RxJava) based implementation. Code example:
  2. ```java
  3. RedissonRxClient client = redissonClient.rxJava();
  4. RAtomicLongRx atomicLong = client.getAtomicLong("myLong");
  5. Single<Boolean> cs = longObject.compareAndSet(10, 91);
  6. Single<Long> get = longObject.get();
  7. get.doOnSuccess(res -> {
  8. // ...
  9. }).subscribe();