@@ -20,11 +20,13 @@ erases stored session information as well.
2020
2121This package wraps the configuration of Laravel's broadcasting, cache, session,
2222and queue APIs for Sentinel with the ability to set options for our Redis
23- services independently. We configure the package separately from Laravel's
24- standard Redis configuration so we can choose to use the Sentinel connections
25- as needed by the environment. A developer may use a standalone Redis server in
26- their local environment, while production environments operate a Redis Sentinel
27- set of servers.
23+ services independently. It adds Sentinel support for [ Laravel Horizon] [ s-horizon ]
24+ and fixes other compatibility issues.
25+
26+ We configure the package separately from Laravel's standard Redis configuration
27+ so we can choose to use the Sentinel connections as needed by the environment.
28+ A developer may use a standalone Redis server in their local environment, while
29+ production environments operate a Redis Sentinel set of servers.
2830
2931
3032Contents
@@ -42,6 +44,7 @@ Contents
4244 - [ Executing Redis Commands (RedisSentinel Facade)] [ s-facade ]
4345 - [ Dependency Injection] [ s-dependency-injection ]
4446 - [ Other Sentinel Considerations] [ s-considerations ]
47+ - [ Laravel Horizon] [ s-horizon ]
4548 - [ Testing] ( #testing )
4649 - [ License] ( #license )
4750 - [ Appendix: Environment Variables] [ s-appx-env-vars ]
@@ -598,6 +601,9 @@ service (`app('redis')`, etc) will operate using the Sentinel connections.
598601This makes it easier for developers to use a standalone Redis server in their
599602local environments and switch to a full Sentinel set of servers in production.
600603
604+ ** Note:** When using the package with [ Laravel Horizon] [ s-horizon ] , this change
605+ will cause Horizon to run over a Sentinel connection as well.
606+
601607
602608Executing Redis Commands (RedisSentinel Facade)
603609-------------------------------------------------
@@ -726,6 +732,67 @@ connection failure handling. For high-availability, use the Laravel API by
726732passing a closure to ` subscribe() ` or ` psubscribe() ` .
727733
728734
735+ Laravel Horizon
736+ ---------------
737+
738+ Versions 2.4.0 and greater of this package provide for the use of Sentinel
739+ connections with the [ Laravel Horizon] [ laravel-horizon ] queue management tool
740+ in compatible applications (Laravel 5.5+).
741+
742+ After [ installing Horizon] [ laravel-horizon-install-docs ] , we need to update
743+ some configuration settings in * config/horizon.php* :
744+
745+ If needed, change ` 'use' => 'default' ` to the name of the Sentinel connection
746+ to use for the Horizon backend as configured in * config/database.php* .
747+
748+ ** Important:** The standard ` 'redis' ` connections array in * config/database.php*
749+ must contain an element with the same key as the Sentinel connection specified
750+ for the ` 'use' ` directive or Horizon throws an exception. Currently, Horizon
751+ does not provide a way for this package to handle this behavior, but an
752+ (in-progress) pull request may eliminate this requirement in the future. This
753+ element can contain any value (but a matching Redis connection config seems
754+ most appropriate).
755+
756+ Change the backend driver for Horizon's internal metadata to ` 'redis-sentinel' `
757+ by adding the following element to the top-level array:
758+
759+ ``` php
760+ 'driver' => env('HORIZON_DRIVER', 'redis');
761+ ```
762+
763+ ...and assign the value of ` redis-sentinel ` to ` HORIZON_DRIVER ` in * .env* .
764+
765+
766+ Then, add an entry to the ` 'waits' ` array for any Sentinel queues:
767+
768+ ``` php
769+ 'waits' => [
770+ ...
771+ 'redis-sentinel:default' => 60,
772+ ],
773+ ```
774+
775+ Next, change the connection driver to ` redis-sentinel ` for each of the queue
776+ workers that should use Sentinel connections in the ` 'environments' ` block:
777+
778+ ``` php
779+ ...
780+ 'supervisor-1' => [
781+ 'connection' => 'redis-sentinel',
782+ ...
783+ ],
784+ ...
785+ ```
786+
787+ Horizon will now use the application's Redis Sentinel connections to monitor
788+ and process our queues.
789+
790+ ** Note:** If we already configured the package to [ override Laravel's standard
791+ Redis API] [ s-override-redis-api ] (by setting ` REDIS_DRIVER ` to ` redis-sentinel ` ,
792+ for example), we don't need to change ` HORIZON_DRIVER ` to ` 'redis-sentinel' ` .
793+ The package already routes all Redis operations through Sentinel connections.
794+
795+
729796Testing
730797-------
731798
@@ -1117,6 +1184,7 @@ Sentinel Documentation][sentinel].
11171184[ s-env-config ] : #environment-based-configuration
11181185[ s-env-config-examples ] : #environment-based-configuration-examples
11191186[ s-facade ] : #executing-redis-commands-redissentinel-facade
1187+ [ s-horizon ] : #laravel-horizon
11201188[ s-hybrid-config ] : #hybrid-configuration
11211189[ s-integration-tests ] : #integration-tests
11221190[ s-multi-sentinel-example ] : #multi-sentinel-connection-configuration
@@ -1129,6 +1197,9 @@ Sentinel Documentation][sentinel].
11291197[ s-standard-config-examples ] : #configuration-file-examples
11301198
11311199[ laravel-env-docs ] : https://laravel.com/docs/configuration#environment-configuration
1200+ [ laravel-horizon ] : https://horizon.laravel.com
1201+ [ laravel-horizon-docs ] : https://laravel.com/docs/horizon
1202+ [ laravel-horizon-install-docs ] : https://laravel.com/docs/horizon#installation
11321203[ laravel-package-discovery-docs ] : https://laravel.com/docs/packages#package-discovery
11331204[ laravel-redis-api-docs ] : https://laravel.com/docs/redis#interacting-with-redis
11341205[ laravel-redis-docs ] : https://laravel.com/docs/redis
0 commit comments