- 1. Overview
- 1. 概述
- 2. Configuration
- 2. 配置方法
- 3. Operations execution
- 3. 程序接口调用方式
- 4. Data serialization
- 4. 数据序列化
- 5. Data partitioning(sharding)
- 5. 单个集合数据分片(Sharding)
- 5.1. Common operations over objects
- 6. Distributed objects
- 6. 分布式对象
- 7. Distributed collections
- 7. 分布式集合
- 8. Distributed locks and synchronizers
- 8. 分布式锁和同步器
- 9. Distributed services
- 9. 分布式服务
- 10. Additional features
- 10. 额外功能
- 11. Redis commands mapping
- 11. Redis 命令和 Redisson 对象匹配列表
- 12. Standalone node
- 12. 独立节点模式
- 13. Tools
- 13. 工具
- 14. Integration with frameworks
- 14. 第三方框架整合
- 15. Dependency list
- 15. 项目依赖列表
- 16. FAQ
- 16. Observability
3. Operations execution
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:
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)));
3.1. Async way
Most Redisson objects extend asynchronous interface with asynchronous methods which mirror to synchronous methods. Like this:
// RAtomicLong extends RAtomicLongAsync
RAtomicLongAsync longObject = client.getAtomicLong("myLong");
RFuture<Boolean> future = longObject.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
});
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:
future.whenCompleteAsync((res, exception) -> {
// handle both result and exception
}, executor);
// or
future.thenAcceptAsync(res -> {
// handle result
}, executor).exceptionallyAsync(exception -> {
// handle exception
}, executor);
3.2. Reactive way
Redisson exposes Reactive Streams API for most objects and based on two implementations:
Project Reactor based implementation. Code example:
RedissonReactiveClient client = redissonClient.reactive();
RAtomicLongReactive atomicLong = client.getAtomicLong("myLong");
Mono cs = longObject.compareAndSet(10, 91);
Mono get = longObject.get();
get.doOnSuccess(res -> { // ... }).subscribe();
RxJava3 based implementation. Code 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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论