@@ -182,10 +182,25 @@ public static function createConnection($dsn, array $options = array())
182
182
183
183
$ redis = $ params ['lazy ' ] ? new RedisClusterProxy ($ initializer ) : $ initializer ();
184
184
} elseif (is_a ($ class , \Predis \Client::class, true )) {
185
- $ params ['scheme ' ] = $ scheme ;
186
- $ params ['database ' ] = $ params ['dbindex ' ] ?: null ;
187
- $ params ['password ' ] = $ auth ;
188
- $ redis = new $ class ((new Factory ())->create ($ params ));
185
+ if ('server ' === $ params ['cluster ' ]) {
186
+ $ host = $ params ['host ' ];
187
+ if (isset ($ params ['port ' ])) {
188
+ $ host .= ': ' .$ params ['port ' ];
189
+ }
190
+
191
+ $ host = array_map (function (\string $ host ) use ($ scheme ): \string {
192
+ return $ scheme .':// ' .$ host ;
193
+ }, explode (', ' , $ host ));
194
+
195
+ // Predis cluster only supports an array of hosts as first argument, otherwise
196
+ // options array is ignored.
197
+ $ redis = new $ class ($ host , array ('cluster ' => 'redis ' ));
198
+ } else {
199
+ $ params ['scheme ' ] = $ scheme ;
200
+ $ params ['database ' ] = $ params ['dbindex ' ] ?: null ;
201
+ $ params ['password ' ] = $ auth ;
202
+ $ redis = new $ class ((new Factory ())->create ($ params ));
203
+ }
189
204
} elseif (class_exists ($ class , false )) {
190
205
throw new InvalidArgumentException (sprintf ('"%s" is not a subclass of "Redis" or "Predis\Client" ' , $ class ));
191
206
} else {
0 commit comments