pyurin/yii2-redis-ha
Composer 安装命令:
composer require pyurin/yii2-redis-ha
包简介
Basic redis-ha client
README 文档
README
This Yii2 component is based on core yii2-redis component https://github.com/yiisoft/yii2-redis but gives ability to work with master-slave redis clusters with sentiels.
It's rather simple - gets master server address from given sentinels and connects to it, then operates just like \yii\redis\Connection.
It works with sentinels only, does not connect to redis hosts without sentinels.
Workflow of connection process
Loop over given sentinels and search for an alive one that will give a master host address.
If a sentinel does not respond or it's respond is empty, then we'll try to check the next one.
If no successfull reply was received, then connection will fail.
After we've found a redis master, we'll connect to it.
If connection to the master server fails, we won't try anything else, we'll fail.
If we sucessfully connect to the master server, we'll then check with role command if it really is master (http://redis.io/topics/sentinel-clients).
If it's not - we'll fail, if it really is - we're sucessfully connected.
Adviced configuration
Redis HA cluster must be done with minimum 2 redis servers and 3 sentinels.
I suppose that in termes of performance, considering this implementation it's better to have a sentinel server for each app locally, to avoid unnecessary overheads.
That would not be important if we cached previously givem master server, but we dont. We ask sentinel each time before connecting to redis.
That's how I see a simple architecture:
------- -------
| | | |
| Redis | | Redis |
| | | |
------- \ /-------
| \ / |
| \ / |
| \-----------/ |
| |\ /| |
| | Sentinel | |
| | . . | |
| --.------.- |
| . . |
| . . |
-----|-------.--- -.----|----------
| | . | | . | |
| Sentinel. . .| . . .|. . Sentinel |
| | | | | |
| (localhost) | | (localhost) |
| | | | | |
| | | | | |
| APP | | APP |
| | | |
----------------- -----------------
Usage
Basic example:
'session' => [
'class' => '\yii\redis\Session',
'redis' => [
'class' => '\pyurin\yii\redisHa\Connection',
'masterName' => 'mymaster',
'sentinels' => [
'localhost'
]
]
],
Sentinel servers are queried in the same order as exist in array.
Installation
Available with composer:
"require" : {
"pyurin/yii2-redis-ha":"*"
},
pyurin/yii2-redis-ha 适用场景与选型建议
pyurin/yii2-redis-ha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 287.4k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2015 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「yii2」 「sentinel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pyurin/yii2-redis-ha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pyurin/yii2-redis-ha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pyurin/yii2-redis-ha 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Microservice RPC through message queues.
A custom URL rule class for Yii 2 which allows to create translated URL rules
The CodeIgniter Redis package
贝嘟分布式缓存扩展
Laravel Dusk for Sentinel.
Redis distributed locks for laravel
统计信息
- 总下载量: 287.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-03-01