关闭

predis client class分析

标签: predis
217人阅读 评论(0) 收藏 举报
分类:

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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2643次
    • 积分:107
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:1篇
    • 译文:2篇
    • 评论:0条
    文章分类