diff --git a/config/reverb.php b/config/reverb.php index bbfd505f..798ead63 100644 --- a/config/reverb.php +++ b/config/reverb.php @@ -40,8 +40,10 @@ 'enabled' => env('REVERB_SCALING_ENABLED', false), 'channel' => env('REVERB_SCALING_CHANNEL', 'reverb'), 'server' => [ + 'url' => env('REDIS_URL'), 'host' => env('REDIS_HOST', '127.0.0.1'), 'port' => env('REDIS_PORT', '6379'), + 'username' => env('REDIS_USERNAME'), 'password' => env('REDIS_PASSWORD'), 'database' => env('REDIS_DB', '0'), ], diff --git a/src/Servers/Reverb/Publishing/RedisPubSubProvider.php b/src/Servers/Reverb/Publishing/RedisPubSubProvider.php index b47a479d..5305e497 100644 --- a/src/Servers/Reverb/Publishing/RedisPubSubProvider.php +++ b/src/Servers/Reverb/Publishing/RedisPubSubProvider.php @@ -3,6 +3,7 @@ namespace Laravel\Reverb\Servers\Reverb\Publishing; use Illuminate\Support\Arr; +use Illuminate\Support\ConfigurationUrlParser; use Illuminate\Support\Facades\Config; use Laravel\Reverb\Servers\Reverb\Contracts\PubSubIncomingMessageHandler; use Laravel\Reverb\Servers\Reverb\Contracts\PubSubProvider; @@ -88,19 +89,35 @@ protected function redisUrl(): string { $config = empty($this->server) ? Config::get('database.redis.default') : $this->server; + $parsed = (new ConfigurationUrlParser())->parseConfiguration($config); + + $driver = strtolower($parsed['driver'] ?? ''); + + if (in_array($driver, ['tcp', 'tls'])) { + $parsed['scheme'] = $driver; + } + + if (in_array($driver, ['tcp', 'tls'])) { + $parsed['scheme'] = $driver; + } + [$host, $port, $protocol, $query] = [ - $config['host'], - $config['port'] ?: 6379, - Arr::get($config, 'scheme') === 'tls' ? 's' : '', + $parsed['host'], + $parsed['port'] ?: 6379, + Arr::get($parsed, 'scheme') === 'tls' ? 's' : '', [], ]; - if ($config['password']) { - $query['password'] = $config['password']; + if ($parsed['username'] ?? false) { + $query['username'] = $parsed['username']; + } + + if ($parsed['password'] ?? false) { + $query['password'] = $parsed['password']; } - if ($config['database']) { - $query['db'] = $config['database']; + if ($parsed['database'] ?? false) { + $query['db'] = $parsed['database']; } $query = http_build_query($query);