Skip to content

API Models

Synchronous and Asynchronous API

Redisson instances are fully thread-safe.

Synchronous and Asynchronous API could be reached via RedissonClient interface.

Most Redisson objects extend asynchronous interface with asynchronous methods which mirrors synchronous methods. Like below:

// RAtomicLong extends RAtomicLongAsync
RAtomicLong obj = client.getAtomicLong("myLong");
obj.compareAndSet(1, 401);

RAtomicLongAsync objAsync = client.getAtomicLong("myLong");
RFuture<Boolean> future = objAsync.compareAndSetAsync(1, 401);
Asynchronous methods return RFuture object which extends CompletionStage interface.

future.whenComplete((res, exception) -> {

    // handle both result and exception

});


// or
future.thenAccept(res -> {

    // handle result

}).exceptionally(exception -> {

    // handle exception

});

Note

Avoid using blocking methods in RFuture listeners. Listeners executed by netty-threads and delays in listeners may cause errors in Redis or Valkey request/response processing.

Use the following methods to execute blocking methods in listeners:

future.whenCompleteAsync((res, exception) -> {

    // handle both result and exception

}, executor);


// or
future.thenAcceptAsync(res -> {

    // handle result

}, executor).exceptionallyAsync(exception -> {

    // handle exception

}, executor);

Reactive API

Reactive API can be reached via RedissonReactiveClient interface.

Redisson's implementation based on Project Reactor.

Usage example:

RedissonReactiveClient client = redissonClient.reactive();

RAtomicLongReactive atomicLong = client.getAtomicLong("myLong");
Mono<Boolean> cs = longObject.compareAndSet(10, 91);
Mono<Long> get = longObject.get();

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

RxJava API

RxJava API can be reached via RedissonRxClient interface.

Redisson's implementation based on RxJava3.

Usage example:

RedissonRxClient client = redissonClient.rxJava();

RAtomicLongRx atomicLong = client.getAtomicLong("myLong");
Single<Boolean> cs = longObject.compareAndSet(10, 91);
Single<Long> get = longObject.get();

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