File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1515 'host ' => env ('REDIS_HOST ' , 'localhost ' ),
1616 'auth ' => env ('REDIS_AUTH ' , null ),
1717 'port ' => (int ) env ('REDIS_PORT ' , 6379 ),
18+ 'cluster ' => env ('REDIS_CLUSTER ' , false ),
1819 'db ' => (int ) env ('REDIS_DB ' , 0 ),
1920 'timeout ' => 0.0 ,
2021 'reserved ' => null ,
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ class RedisConnection extends BaseConnection implements ConnectionInterface
3232 'host ' => 'localhost ' ,
3333 'port ' => 6379 ,
3434 'auth ' => null ,
35+ 'cluster ' => false ,
3536 'db ' => 0 ,
3637 'timeout ' => 0.0 ,
3738 'options ' => [],
@@ -74,12 +75,24 @@ public function reconnect(): bool
7475 $ host = $ this ->config ['host ' ];
7576 $ port = $ this ->config ['port ' ];
7677 $ auth = $ this ->config ['auth ' ];
78+ $ cluster = $ this ->config ['cluster ' ];
7779 $ db = $ this ->config ['db ' ];
7880 $ timeout = $ this ->config ['timeout ' ];
7981
80- $ redis = new \Redis ();
81- if (! $ redis ->connect ($ host , $ port , $ timeout )) {
82- throw new ConnectionException ('Connection reconnect failed. ' );
82+ $ redis = null ;
83+ if ($ cluster !== true ) {
84+ // Normal Redis (Non-cluster)
85+ $ redis = new \Redis ();
86+ if (! $ redis ->connect ($ host , $ port , $ timeout )) {
87+ throw new ConnectionException ('Connection reconnect failed. ' );
88+ }
89+ } else {
90+ // Redis Cluster
91+ try {
92+ $ redis = new \RedisCluster (null , [$ host . ': ' . $ port ], $ timeout );
93+ } catch (\Throwable $ e ) {
94+ throw new ConnectionException ('Connection reconnect failed. ' . $ e ->getMessage ());
95+ }
8396 }
8497
8598 $ options = $ this ->config ['options ' ] ?? [];
You can’t perform that action at this time.
0 commit comments