predis client class分析

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值