4
4
5
5
use Illuminate \Support \Arr ;
6
6
use Illuminate \Redis \Connectors \PhpRedisConnector as LaravelPhpRedisConnector ;
7
+ use LogicException ;
7
8
use Monospice \LaravelRedisSentinel \Connections \PhpRedisConnection ;
8
9
use Redis ;
9
10
use RedisSentinel ;
@@ -88,10 +89,13 @@ public function connect(array $servers, array $options = [ ])
88
89
*
89
90
* @param array $options
90
91
* @return Redis
92
+ *
93
+ * @throws LogicException
91
94
*/
92
95
protected function createClientWithSentinel (array $ options )
93
96
{
94
97
$ servers = $ this ->servers ;
98
+ $ service = isset ($ options ['service ' ]) ? $ options ['service ' ] : 'mymaster ' ;
95
99
$ timeout = isset ($ options ['sentinel_timeout ' ]) ? $ options ['sentinel_timeout ' ] : 0 ;
96
100
$ persistent = isset ($ options ['sentinel_peristent ' ]) ? $ options ['sentinel_peristent ' ] : null ;
97
101
$ retryWait = isset ($ options ['retry_wait ' ]) ? $ options ['retry_wait ' ] : 0 ;
@@ -101,11 +105,20 @@ protected function createClientWithSentinel(array $options)
101
105
// Shuffle the servers to perform some loadbalancing.
102
106
shuffle ($ servers );
103
107
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
+
104
118
// Try to connect to any of the servers.
105
119
foreach ($ servers as $ idx => $ server ) {
106
120
$ host = isset ($ server ['host ' ]) ? $ server ['host ' ] : 'localhost ' ;
107
121
$ port = isset ($ server ['port ' ]) ? $ server ['port ' ] : 26739 ;
108
- $ service = isset ($ options ['service ' ]) ? $ options ['service ' ] : 'mymaster ' ;
109
122
110
123
// Create a connection to the Sentinel instance.
111
124
$ sentinel = new RedisSentinel ($ host , $ port , $ timeout , $ persistent , $ retryWait , $ readTimeout );
0 commit comments