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连接-》访问数据

阅读更多
文章标签: predis
个人分类: Redis
上一篇redis python客户端(redis-py)分析
下一篇协程资料
想对作者说点什么? 我来说一句

thinkphp_redis

2015年05月08日 4KB 下载

没有更多推荐了,返回首页

关闭
关闭