rabin hace 1 día
padre
commit
3578e7113c
Se han modificado 1 ficheros con 22 adiciones y 8 borrados
  1. 22 8
      src/Dever/Helper/Redis.php

+ 22 - 8
src/Dever/Helper/Redis.php

@@ -7,11 +7,11 @@ class Redis
     private static $handle;
     private static $expire = 3600;
 
-    public static function connect()
-    {
-        if (!self::$handle) {
-            $config = \Dever::config('setting')['redis'] ?? false;
-            if (!$config) {
+    public static function connect()
+    {
+        if (!self::$handle) {
+            $config = \Dever::config('setting')['redis'] ?? false;
+            if (!$config) {
                 \Dever::error('redis error');
             }
 
@@ -24,9 +24,23 @@ class Redis
             }
 
             self::$handle->setOption(\Redis::OPT_READ_TIMEOUT, -1);
-        }
-        return self::$handle;
-    }
+        }
+        return self::$handle;
+    }
+
+    public static function reconnect()
+    {
+        if (self::$handle) {
+            try {
+                self::$handle->close();
+            } catch (\Throwable $e) {
+                // ignore close failure
+            }
+            self::$handle = null;
+        }
+
+        return self::connect();
+    }
 
     /** -------------------------
      *  KV 基础操作