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);
future.whenComplete((res, exception) -> {
// handle both result and exception
});
// or
future.thenAccept(res -> {
// handle result
}).exceptionally(exception -> {
// handle exception
});
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 could 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 could 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();
Retry policy¶
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 or Valkey 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:
RedissonClient client = Redisson.create(config);
RBucket<MyObject> bucket = client.getBucket('myObject');
// sync way
bucket.get();
// async way
RFuture<MyObject> result = bucket.getAsync();
// instance with overridden retryInterval and timeout parameters
RBucket<MyObject> bucket = client.getBucket(PlainOptions.name('myObject')
.timeout(Duration.ofSeconds(3))
.retryInterval(Duration.ofSeconds(5)));