From e4bed34cea6fd274ac3250d0780ca993e390a3aa Mon Sep 17 00:00:00 2001 From: Martin Himmel Date: Fri, 19 Apr 2024 14:42:01 -0400 Subject: [PATCH] Add configuration for Redis clusters --- config/reverb.php | 1 + src/Servers/Reverb/Publishing/RedisPubSubProvider.php | 5 +++-- src/Servers/Reverb/ReverbServerProvider.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/config/reverb.php b/config/reverb.php index 2ee4bce4..45cb99a5 100644 --- a/config/reverb.php +++ b/config/reverb.php @@ -39,6 +39,7 @@ 'scaling' => [ 'enabled' => env('REVERB_SCALING_ENABLED', false), 'channel' => env('REVERB_SCALING_CHANNEL', 'reverb'), + 'cluster_enabled' => env('REVERB_SCALING_CLUSTER_ENABLED', false), ], 'pulse_ingest_interval' => env('REVERB_PULSE_INGEST_INTERVAL', 15), 'telescope_ingest_interval' => env('REVERB_TELESCOPE_INGEST_INTERVAL', 15), diff --git a/src/Servers/Reverb/Publishing/RedisPubSubProvider.php b/src/Servers/Reverb/Publishing/RedisPubSubProvider.php index 10663567..ad21ebce 100644 --- a/src/Servers/Reverb/Publishing/RedisPubSubProvider.php +++ b/src/Servers/Reverb/Publishing/RedisPubSubProvider.php @@ -19,7 +19,8 @@ class RedisPubSubProvider implements PubSubProvider public function __construct( protected RedisClientFactory $clientFactory, protected PubSubIncomingMessageHandler $messageHandler, - protected string $channel + protected string $channel, + protected bool $clusterMode = false ) { // } @@ -85,7 +86,7 @@ public function publish(array $payload): PromiseInterface */ protected function redisUrl(): string { - $config = Config::get('database.redis.default'); + $config = Config::get($this->clusterMode ? 'database.redis.clusters.default.0' : 'database.redis.default'); [$host, $port, $protocol, $query] = [ $config['host'], diff --git a/src/Servers/Reverb/ReverbServerProvider.php b/src/Servers/Reverb/ReverbServerProvider.php index f0338bf1..3b1549eb 100644 --- a/src/Servers/Reverb/ReverbServerProvider.php +++ b/src/Servers/Reverb/ReverbServerProvider.php @@ -37,7 +37,8 @@ public function register(): void $this->app->singleton(PubSubProvider::class, fn ($app) => new RedisPubSubProvider( $app->make(RedisClientFactory::class), $app->make(PubSubIncomingMessageHandler::class), - $this->config['scaling']['channel'] ?? 'reverb' + $this->config['scaling']['channel'] ?? 'reverb', + $this->config['scaling']['cluster_enabled'] ?? false )); }