laravel / reverb

Laravel Reverb provides a real-time WebSocket communication backend for Laravel applications.
https://reverb.laravel.com
MIT License
1.02k stars 71 forks source link

Add configuration for Redis cluster support #166

Closed MartyHimmel closed 4 months ago

MartyHimmel commented 4 months ago

This adds a configuration setting and check to allow Redis in cluster mode (see issue #160). Adding REVERB_SCALING_CLUSTER_ENABLED=true to the .env file will change the config used from database.redis.default to database.redis.clusters.default.0. Like the horizontal scaling feature, this is off by default.

taylorotwell commented 4 months ago

Hey @MartyHimmel - I would maybe take a slightly different approach here and instead let you actually specify the entire Redis connection information if you want.

Something like:

'scaling' => [
    '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'),
          'username' => env('REDIS_USERNAME'),
          'password' => env('REDIS_PASSWORD'),
          'port' => env('REDIS_PORT', '6379'),
          'database' => env('REDIS_DB', '0'),
    ],
],

Then pass that info into the PubSub class as an array. It's a bit more verbose on the configuration side but I think more flexible.

MartyHimmel commented 4 months ago

Thanks for the direction @taylorotwell! This is my first contribution to any part of Laravel, so I was trying to keep it minimal. 😅

The updated config is working well except for the failing Laravel 10 test. I'll push another update as soon as I figure out what's going on there.

MartyHimmel commented 4 months ago

Digging into that a bit more, it seems like the failing test above is unrelated (appears to be happening on the main branch, too). Is there anything else I need to do with this?

MartyHimmel commented 4 months ago

@joedixon Done and done.

joedixon commented 4 months ago

Thanks @MartyHimmel - just want to confirm, this configuration works with your cluster?

MartyHimmel commented 4 months ago

@joedixon Yep. I tried it on a localhost setup Friday and the server started. Just tried it on my work's dev environment (that's the one that uses AWS with the Elasticache/Redis cluster) and it started up without any issues.

Thanks again for yours and Taylor's direction! I'm excited to dig into this more and finally move our app out of long polling and into websockets. 😁