1818use  Hyperf \Pool \Exception \ConnectionException ;
1919use  Hyperf \Redis \Exception \InvalidRedisConnectionException ;
2020use  Psr \Container \ContainerInterface ;
21+ use  Redis ;
22+ use  RedisCluster ;
23+ use  RedisException ;
24+ use  RedisSentinel ;
25+ use  Throwable ;
2126
2227/** 
2328 * @method bool select(int $db) 
@@ -26,7 +31,7 @@ class RedisConnection extends BaseConnection implements ConnectionInterface
2631{
2732    use  ScanCaller;
2833
29-     protected  \ Redis \ RedisCluster null  $ connectionnull ;
34+     protected  Redis RedisCluster null  $ connectionnull ;
3035
3136    protected  array  $ config
3237        'host '  => 'localhost ' ,
@@ -73,7 +78,7 @@ public function __call($name, $arguments)
7378    {
7479        try  {
7580            $ result$ this connection ->{$ name$ arguments
76-         } catch  (\ Throwable $ exception
81+         } catch  (Throwable $ exception
7782            $ result$ this retry ($ name$ arguments$ exception
7883        }
7984
@@ -94,7 +99,7 @@ public function getActiveConnection()
9499    }
95100
96101    /** 
97-      * @throws \ RedisException 
102+      * @throws RedisException 
98103     * @throws ConnectionException 
99104     */ 
100105    public  function  reconnect (): bool 
@@ -117,7 +122,7 @@ public function reconnect(): bool
117122            $ redissetOption ($ name$ value
118123        }
119124
120-         if  ($ redisinstanceof  \ Redis && isset ($ auth$ auth'' ) {
125+         if  ($ redisinstanceof  Redis && isset ($ auth$ auth'' ) {
121126            $ redisauth ($ auth
122127        }
123128
@@ -154,7 +159,7 @@ public function setDatabase(?int $database): void
154159        $ this database  = $ database
155160    }
156161
157-     protected  function  createRedisCluster (): \ RedisCluster 
162+     protected  function  createRedisCluster (): RedisCluster 
158163    {
159164        try  {
160165            $ parameters
@@ -170,23 +175,23 @@ protected function createRedisCluster(): \RedisCluster
170175                $ parameters$ this config ['cluster ' ]['context ' ];
171176            }
172177
173-             $ redisnew  \ RedisCluster (...$ parameters
174-         } catch  (\ Throwable $ e
178+             $ redisnew  RedisCluster (...$ parameters
179+         } catch  (Throwable $ e
175180            throw  new  ConnectionException ('Connection reconnect failed  '  . $ egetMessage ());
176181        }
177182
178183        return  $ redis
179184    }
180185
181-     protected  function  retry ($ name$ arguments\ Throwable $ exception
186+     protected  function  retry ($ name$ argumentsThrowable $ exception
182187    {
183188        $ logger$ this container ->get (StdoutLoggerInterface::class);
184189        $ loggerwarning ('Redis::__call failed, because  '  . $ exceptiongetMessage ());
185190
186191        try  {
187192            $ this reconnect ();
188193            $ result$ this connection ->{$ name$ arguments
189-         } catch  (\ Throwable $ exception
194+         } catch  (Throwable $ exception
190195            $ this lastUseTime  = 0.0 ;
191196            throw  $ exception
192197        }
@@ -197,7 +202,7 @@ protected function retry($name, $arguments, \Throwable $exception)
197202    /** 
198203     * @throws ConnectionException 
199204     */ 
200-     protected  function  createRedisSentinel (): \ Redis 
205+     protected  function  createRedisSentinel (): Redis 
201206    {
202207        try  {
203208            $ nodes$ this config ['sentinel ' ]['nodes ' ] ?? [];
@@ -214,7 +219,7 @@ protected function createRedisSentinel(): \Redis
214219            foreach  ($ nodesas  $ node
215220                try  {
216221                    [$ sentinelHost$ sentinelPortexplode (': ' , $ node
217-                     $ sentinelnew  \ RedisSentinel (
222+                     $ sentinelnew  RedisSentinel (
218223                        $ sentinelHost
219224                        intval ($ sentinelPort
220225                        $ timeout
@@ -228,7 +233,7 @@ protected function createRedisSentinel(): \Redis
228233                        [$ host$ port$ masterInfo
229234                        break ;
230235                    }
231-                 } catch  (\ Throwable $ exception
236+                 } catch  (Throwable $ exception
232237                    $ logger$ this container ->get (StdoutLoggerInterface::class);
233238                    $ loggerwarning ('Redis sentinel connection failed, caused by  '  . $ exceptiongetMessage ());
234239                    continue ;
@@ -246,7 +251,7 @@ protected function createRedisSentinel(): \Redis
246251                'retry_interval '  => $ retryInterval
247252                'read_timeout '  => $ readTimeout
248253            ]);
249-         } catch  (\ Throwable $ e
254+         } catch  (Throwable $ e
250255            throw  new  ConnectionException ('Connection reconnect failed  '  . $ egetMessage ());
251256        }
252257
@@ -255,9 +260,9 @@ protected function createRedisSentinel(): \Redis
255260
256261    /** 
257262     * @throws ConnectionException 
258-      * @throws \ RedisException 
263+      * @throws RedisException 
259264     */ 
260-     protected  function  createRedis (array  $ config\ Redis 
265+     protected  function  createRedis (array  $ configRedis 
261266    {
262267        $ parameters
263268            $ config'host ' ] ?? '' ,
@@ -272,7 +277,7 @@ protected function createRedis(array $config): \Redis
272277            $ parameters$ config'context ' ];
273278        }
274279
275-         $ redisnew  \ Redis ();
280+         $ redisnew  Redis ();
276281        if  (! $ redisconnect (...$ parameters
277282            throw  new  ConnectionException ('Connection reconnect failed. ' );
278283        }
0 commit comments