cooperaj/laravel-redis-sentinel
Composer 安装命令:
composer require cooperaj/laravel-redis-sentinel
包简介
Provides a laravel queue driver that works with Redis Sentinels.
README 文档
README
This provides a Sentinel aware driver for Laravel. A Redis cluster with Sentinels supports a high availability Master/Slave architecture that provides automatic failover should a node stop working.
It's simple code and merely allows you to configure Sentinels correctly by changing some assumptions Laravel makes about how you're using Redis.
Compatibility
| Version | Supported Laravel Version |
|---|---|
| ^0.0 | ^5.2 |
| ^1.0 | ^5.3 |
Installation
Add the Service provider to your config/app.php, you should also comment out (or remove) the default illuminate Redis driver:
'providers' => [
// Illuminate\Redis\RedisServiceProvider::class,
...
RedisSentinel\Laravel\RedisSentinelServiceProvider::class,
]
Point your Redis database at a set of Redis Sentinels. Change the redis part of your config/database.php to something like:
'redis' => [
'cluster' => false,
'default' => [
[
'host' => env('REDIS_SENTINEL_1'),
'port' => 26379
],
[
'host' => env('REDIS_SENTINEL_2'),
'port' => 26379
],
[
'host' => env('REDIS_SENTINEL_3'),
'port' => 26379
],
'options' => [
'replication' => 'sentinel',
'service' => 'mymaster',
'parameters' => [
'database' => 0,
'password' => env('REDIS_PASSWORD', null)
]
]
],
// optional configuration for a separate Redis 'database' for just a cache
'cache' => [
[
'host' => env('REDIS_SENTINEL_1'),
'port' => 26379
],
[
'host' => env('REDIS_SENTINEL_2'),
'port' => 26379
],
[
'host' => env('REDIS_SENTINEL_3'),
'port' => 26379
],
'options' => [
'replication' => 'sentinel',
'service' => 'mymaster',
'parameters' => [
'database' => 1, // note the differing 'database' number
'password' => env('REDIS_PASSWORD', null)
]
]
],
'options' => [
]
],
Optionally you can add a configuration option that causes Predis to interrogate a given Sentinel for a complete list of Sentinels. If you do this then you only need to provide a single Sentinel in the configuration. Predis will ensure that the Sentinel list is kept up to date on subsequent queries.
'default' => [
[
'host' => env('REDIS_SENTINEL'),
'port' => 26379
],
'options' => [
'replication' => 'sentinel',
'service' => 'mymaster',
'update_sentinels' => true,
'parameters' => [
'database' => 0,
'password' => env('REDIS_PASSWORD', null)
]
]
],
Queue
Add a connection to your config/queue.php file:
'connections' => [
...
'sentinel' => [
'driver' => 'sentinel-redis',
'connection' => 'default', // or any other named 'database' you define in database.php
'queue' => 'default',
'retry_after' => 90,
],
],
Configure your env file to use the new driver:
QUEUE_DRIVER=sentinel
Cache
Laravel will quite happily use Redis as a cache location. What they don't tell you is that clearing your cache does a simplistic FLUSHDB command. Something you don't want to use if you're also using queues in Redis. "Oh no, all my queued jobs have disappeared".
To fix this setup a cache database configuration as shown in the example config/database.php snippet above, ensuring that you use a different database number and change the Redis section of config/cache.php to read:
'redis' => [
'driver' => 'redis',
'connection' => 'cache', \\ make sure this matches the name you gave your 'database'
],
cooperaj/laravel-redis-sentinel 适用场景与选型建议
cooperaj/laravel-redis-sentinel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31.45k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2016 年 07 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cooperaj/laravel-redis-sentinel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cooperaj/laravel-redis-sentinel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 31.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-21