Explorar el Código

:bug: redis连接加错误处理

visuddhinanda hace 4 años
padre
commit
65920c0a1b
Se han modificado 1 ficheros con 14 adiciones y 7 borrados
  1. 14 7
      app/redis/function.php

+ 14 - 7
app/redis/function.php

@@ -1,11 +1,18 @@
 <?php
 function redis_connect()
 {
-    $redis = new redis();
-    $r_conn = $redis->connect('127.0.0.1', 6379);
-    if ($r_conn) {
-        return $redis;
-    } else {
-        return false;
-    }
+	try {
+		//code...
+		$redis = new redis();
+		$r_conn = $redis->connect('127.0.0.1', 6379);
+		if ($r_conn) {
+			return $redis;
+		} else {
+			return false;
+		}		
+	} catch (\Throwable $th) {
+		//throw $th;
+		return false;
+	}
+
 }