Using Redis cluster throws a null error
MartyHimmel opened this issue · comments
Reverb Version
1.0.0-beta7
Laravel Version
11.4.0
PHP Version
8.3.6
Description
I have a project that's hosted on AWS behind a load balancer that uses a Redis cluster. When trying to enable horizontal scaling and starting the reverb server, I'm getting this error:
Trying to access array offset on null at vendor/laravel/reverb/src/Servers/Reverb/Publishing/RedisPubSubProvider.php:81
protected function redisUrl(): string {
78▕ $config = Config::get('database.redis.default');
79▕
80▕ [$host, $port, $protocol, $query] = [
➜ 81▕ $config['host'],
82▕ $config['port'] ?: 6379,
83▕ 'tls' === Arr::get($config, 'scheme') ? 's' : '',
84▕ [],
85▕ ];
Since the config uses a cluster setup (database.redis.clusters.default
and database.redis.clusters.cache
), the database.redis.default
key doesn't exist, which is causing the null
errors.
Any help/guidance on this would be appreciated!
Steps To Reproduce
.env
:
REDIS_HOST=<AWS endpoint>
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_QUEUE={default}
REVERB_APP_ID=<id>
REVERB_APP_KEY=<key>
REVERB_APP_SECRET=<secret>
REVERB_HOST=<domain>
REVERB_PORT=8080
REVERB_SCHEME=https
REVERB_SCALING_ENABLED=true
Since we use an AWS endpoint for the cluster, there is no REDIS_URL
key.
config/database.php
:
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
],
'clusters' => [
'cache' => [
[
'url' => env('REDIS_URL'), // not used
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_CACHE_DB', '1'),
],
],
'default' => [
[
'url' => env('REDIS_URL'), // not used
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
],
],
],
],
Run php artisan reverb:start
@MartyHimmel Reverb doesn't support Redis clusters right now, but I will add this to the backlog to explore.
Also open to a PR if you manage to make it work.