#113071 Замена predis для работы с sentinel
This commit is contained in:
commit
b39978eca9
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "dominion/laravel-redis-sentinel",
|
||||
"description": "Множественность серверов sentinel",
|
||||
"keywords": ["laravel","redis", "sentinel"],
|
||||
"homepage": "https://gitea.optiweb.ru/public/kuvalda-laravel-redis-sentinel",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Rybkin Sasha",
|
||||
"email": "ribkin@dominion.ru"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"namoshek/laravel-redis-sentinel": "^0.8|^0.9"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"dominion\\laravel-redis-sentinel\\": "src"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Dominion\\Redis\\Sentinel\\RedisSentinelServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dominion\Redis\Sentinel\Connectors;
|
||||
|
||||
use RedisSentinel;
|
||||
|
||||
/**
|
||||
* Allows to connect to a Sentinel driven Redis master using the PhpRedis extension.
|
||||
*/
|
||||
class PhpRedisSentinelConnector extends \Namoshek\Redis\Sentinel\Connectors\PhpRedisSentinelConnector
|
||||
{
|
||||
|
||||
private function connectToSentinel(array $config): RedisSentinel
|
||||
{
|
||||
$hosts = is_array($config['sentinel_host']) ? $config['sentinel_host'] : [$config['sentinel_host']];
|
||||
foreach ($hosts as $host)
|
||||
{
|
||||
$newConfig = $config;
|
||||
$newConfig['sentinel_host'] = $host;
|
||||
$RedisSentinel = parent::connectToSentinel($newConfig);
|
||||
if($RedisSentinel->ping())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $RedisSentinel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dominion\Redis\Sentinel;
|
||||
|
||||
use Illuminate\Redis\RedisManager;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Dominion\Redis\Sentinel\Connectors\PhpRedisSentinelConnector;
|
||||
|
||||
/**
|
||||
* Registers and boots services of the Laravel Redis Sentinel package.
|
||||
*/
|
||||
class RedisSentinelServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->extend('redis', function (RedisManager $service) {
|
||||
return $service->extend('dominion-phpredis-sentinel', fn () => new PhpRedisSentinelConnector);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue