@@ -34,12 +34,16 @@ class RedisConnection extends BaseConnection implements ConnectionInterface
3434        'auth '  => null ,
3535        'db '  => 0 ,
3636        'timeout '  => 0.0 ,
37+         'reserved '  => null ,
38+         'retry_interval '  => 0 ,
39+         'read_timeout '  => 0.0 ,
3740        'cluster '  => [
3841            'enable '  => false ,
3942            'name '  => null ,
4043            'seeds '  => [],
4144            'read_timeout '  => 0.0 ,
4245            'persistent '  => false ,
46+             'context '  => [],
4347        ],
4448        'sentinel '  => [
4549            'enable '  => false ,
@@ -49,6 +53,7 @@ class RedisConnection extends BaseConnection implements ConnectionInterface
4953            'read_timeout '  => 0 ,
5054        ],
5155        'options '  => [],
56+         'context '  => [],
5257    ];
5358
5459    /** 
@@ -88,20 +93,21 @@ public function getActiveConnection()
8893        return  $ this 
8994    }
9095
96+     /** 
97+      * @throws \RedisException 
98+      * @throws ConnectionException 
99+      */ 
91100    public  function  reconnect (): bool 
92101    {
93-         $ host$ this config ['host ' ];
94-         $ port$ this config ['port ' ];
95102        $ auth$ this config ['auth ' ];
96103        $ db$ this config ['db ' ];
97-         $ timeout$ this config ['timeout ' ];
98104        $ cluster$ this config ['cluster ' ]['enable ' ] ?? false ;
99105        $ sentinel$ this config ['sentinel ' ]['enable ' ] ?? false ;
100106
101107        $ redismatch  (true ) {
102108            $ cluster$ this createRedisCluster (),
103109            $ sentinel$ this createRedisSentinel (),
104-             default  => $ this createRedis ($ host ,  $ port ,  $ timeout 
110+             default  => $ this createRedis ($ this -> config ),
105111        };
106112
107113        $ options$ this config ['options ' ] ?? [];
@@ -160,6 +166,9 @@ protected function createRedisCluster(): \RedisCluster
160166            if  (isset ($ this config ['auth ' ])) {
161167                $ parameters$ this config ['auth ' ];
162168            }
169+             if  (! empty ($ this config ['cluster ' ]['context ' ])) {
170+                 $ parameters$ this config ['cluster ' ]['context ' ];
171+             }
163172
164173            $ redisnew  \RedisCluster (...$ parameters
165174        } catch  (\Throwable   $ e
@@ -185,6 +194,9 @@ protected function retry($name, $arguments, \Throwable $exception)
185194        return  $ result
186195    }
187196
197+     /** 
198+      * @throws ConnectionException 
199+      */ 
188200    protected  function  createRedisSentinel (): \Redis  
189201    {
190202        try  {
@@ -227,7 +239,13 @@ protected function createRedisSentinel(): \Redis
227239                throw  new  InvalidRedisConnectionException ('Connect sentinel redis server failed. ' );
228240            }
229241
230-             $ redis$ this createRedis ($ host$ port$ timeout
242+             $ redis$ this createRedis ([
243+                 'host '  => $ host
244+                 'port '  => $ port
245+                 'timeout '  => $ timeout
246+                 'retry_interval '  => $ retryInterval
247+                 'read_timeout '  => $ readTimeout
248+             ]);
231249        } catch  (\Throwable   $ e
232250            throw  new  ConnectionException ('Connection reconnect failed  '  . $ egetMessage ());
233251        }
@@ -236,14 +254,26 @@ protected function createRedisSentinel(): \Redis
236254    }
237255
238256    /** 
239-      * @param string $host 
240-      * @param int $port 
241-      * @param float $timeout 
257+      * @throws ConnectionException 
258+      * @throws \RedisException 
242259     */ 
243-     protected  function  createRedis ($ host ,  $ port ,  $ timeout \Redis  
260+     protected  function  createRedis (array   $ config \Redis  
244261    {
262+         $ parameters
263+             $ config'host ' ] ?? '' ,
264+             $ config'port ' ] ?? 6379 ,
265+             $ config'timeout ' ] ?? 0.0 ,
266+             $ config'reserved ' ] ?? null ,
267+             $ config'retry_interval ' ] ?? 0 ,
268+             $ config'read_timeout ' ] ?? 0.0 ,
269+         ];
270+ 
271+         if  (! empty ($ config'context ' ])) {
272+             $ parameters$ config'context ' ];
273+         }
274+ 
245275        $ redisnew  \Redis ();
246-         if  (! $ redisconnect (( string )  $ host , ( int )  $ port ,  $ timeout 
276+         if  (! $ redisconnect (... $ parameters 
247277            throw  new  ConnectionException ('Connection reconnect failed. ' );
248278        }
249279        return  $ redis
0 commit comments