Skip to content

Commit

Permalink
adds redis url support
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Apr 24, 2024
1 parent 78d8db3 commit 998e597
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config/reverb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
Expand Down
31 changes: 24 additions & 7 deletions src/Servers/Reverb/Publishing/RedisPubSubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 998e597

Please sign in to comment.