以例子AtomicDouble为例分析下执行过程
- 从RedissonAtomicDouble可以看出所有Sync操作实际都是同步调用CommandAsyncService 的get分析Async future结果返回完成
- 通过分析 this(commandExecutor.getConnectionManager().getCodec(),
commandExecutor, name);
可以知道默认使用org.redisson.codec.JsonJacksonCodec及org.redisson.command.CommandSyncService - 异步过程有一个关键数据类:AsyncDetail,命令、各种promise、future都保存在这个类中
- 所有发送命令,最终进入CommandAsyncService 的sendCommand方法,调用RedisConnection的send方法
- send方法写入后,由class commandsQueue执行,commandsQueue是一个netty的ContextHandler,在public class RedisChannelInitializer 的protected void initChannel(Channel ch)函数中被声明
- 对具体执行过程可以参考https://blog.csdn.net/zilong_zilong/article/details/78609423,但请注意版本比较旧