[ Web Proxy ]
URL:
Viewing: https://redisson.pro/docs/api-models/#rxjava-api [Back]  [Original]

API Models - Redisson Reference Guide
Skip to content
logo [logo]
Redisson Reference Guide
API Models
GitHub

API Models

Redisson offers four API models synchronous, asynchronous, reactive, and RxJava3 described in the sections below.

Synchronous and Asynchronous API

Redisson instances are fully thread-safe.

Synchronous and Asynchronous API could be reached via RedissonClient interface.

Most Redisson objects implement an asynchronous interface whose asynchronous methods mirror the synchronous ones, as shown 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 are executed by netty threads, and delays in them 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 = atomicLong.compareAndSet(10, 91);
Mono<Long> get = atomicLong.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 = atomicLong.compareAndSet(10, 91);
Single<Long> get = atomicLong.get();

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

Web Proxy Viewer  |  New URL  |  Original Page