predis client class分析

来源:互联网 发布:深圳飞扬数码通讯淘宝 编辑:程序博客网 时间:2024/05/29 09:37

Client-> construct

construct -> options, connection, profile, getClientFor->getConnectionById

connection-> connections->create, getConnectionInitializerWrapper/initializer, connections->aggregate->Factory

_call -> executeRaw , createCommand/executeCommand->parseResponse,onErrorResponse(重试逻辑)

ClientContextInterface
pipeline, transaction -> sharedContextFactory, createPipeline / createTransaction

pubSubLoop -> sharedContextFactory, createPubSub->PubSubConsumer
monitor -> MonitorConsumer

重点类
Client 客户端封装类
Options 配置封装类

AbstractConnection 连接类(StreamConnection)->NodeConnectionInterface
AggregateConnectionInterface 组合交互连接

集群交互类(aggregate)
RedisCluster->ClusterStrategy->RedisStrategy(Command->Slot)
PredisCluster->ClusterStrategy->PredisStrategy
SentinelReplication->MaterSlaveReplication->ReplicationStrategy

命令抽象类
Command

功能特性类
Pipeline
Transaction
PubSub
Monitor

辅助类
Cluster Replication 集群策略类
Collection Redis数据结构辅助类
Profile Redis版本信息类
Response 结果处理工具类

协议扩展类
Protocol

RedisCluster类分析
负责处理Redis集群节点的连接管理

sentinel重点关注
SentinelReplication
ReplicationStrategy

接口数据结构分析
client 初始化: options->connections->ReplicationOption->SentinelReplication
建立连接:client->connection(=>SentinelReplication)
->current(getmaster/pickslave=>StreamConnection)->connect()->stream_socket_client();
普通命令:createCommand : client->profile(redisprofile)->createCommand=>Command
executeCommand: client->connection(=>SentinelReplication)
->getConnection(=>StreamConnection)->writeRequest/readResponse
组合命令:pipeline/transaction/PubSubConsumer/MonitorConsumer 共同继承ClientContextInterface
pipeline(callback)-> [pipeline->enqueue()] / executePipeline-> for(writeRequest) / for(readResponse)
哨兵模式:
SentinelReplication:参数sentinels(哨兵地址)和service(实例名称)
工厂类Factory用于创建连接类StreamConnection
策略类ReplicationStrategy用于选择连接节点,辅助判断读写分离
sentinel参数-》sentinel连接-》current/master/slave信息-》校验ROLE-》node连接-》访问数据

0 0
原创粉丝点击