44
55use Illuminate \Support \Arr ;
66use Illuminate \Redis \Connectors \PhpRedisConnector as LaravelPhpRedisConnector ;
7+ use LogicException ;
78use Monospice \LaravelRedisSentinel \Connections \PhpRedisConnection ;
89use Redis ;
910use RedisSentinel ;
@@ -88,10 +89,13 @@ public function connect(array $servers, array $options = [ ])
8889 *
8990 * @param array $options
9091 * @return Redis
92+ *
93+ * @throws LogicException
9194 */
9295 protected function createClientWithSentinel (array $ options )
9396 {
9497 $ servers = $ this ->servers ;
98+ $ service = isset ($ options ['service ' ]) ? $ options ['service ' ] : 'mymaster ' ;
9599 $ timeout = isset ($ options ['sentinel_timeout ' ]) ? $ options ['sentinel_timeout ' ] : 0 ;
96100 $ persistent = isset ($ options ['sentinel_peristent ' ]) ? $ options ['sentinel_peristent ' ] : null ;
97101 $ retryWait = isset ($ options ['retry_wait ' ]) ? $ options ['retry_wait ' ] : 0 ;
@@ -101,11 +105,20 @@ protected function createClientWithSentinel(array $options)
101105 // Shuffle the servers to perform some loadbalancing.
102106 shuffle ($ servers );
103107
108+ // Check if the redis extension is enabled.
109+ if (! extension_loaded ('redis ' )) {
110+ throw new LogicException ('Please make sure the PHP Redis extension is installed and enabled. ' );
111+ }
112+
113+ // Check if the extension is up to date and contains RedisSentinel.
114+ if (! class_exists (RedisSentinel::class)) {
115+ throw new LogicException ('Please make sure the PHP Redis extension is up to date. ' );
116+ }
117+
104118 // Try to connect to any of the servers.
105119 foreach ($ servers as $ idx => $ server ) {
106120 $ host = isset ($ server ['host ' ]) ? $ server ['host ' ] : 'localhost ' ;
107121 $ port = isset ($ server ['port ' ]) ? $ server ['port ' ] : 26739 ;
108- $ service = isset ($ options ['service ' ]) ? $ options ['service ' ] : 'mymaster ' ;
109122
110123 // Create a connection to the Sentinel instance.
111124 $ sentinel = new RedisSentinel ($ host , $ port , $ timeout , $ persistent , $ retryWait , $ readTimeout );
0 commit comments