From cf5d5059d77c2ae46b59f8e483f8de6f772eaaf0 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Sun, 14 Sep 2025 16:07:34 +0800 Subject: [PATCH] feat : common redis cache --- app/Cache/Redis/BaseScript.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/Cache/Redis/BaseScript.php b/app/Cache/Redis/BaseScript.php index 4e38370..df2749b 100644 --- a/app/Cache/Redis/BaseScript.php +++ b/app/Cache/Redis/BaseScript.php @@ -5,9 +5,8 @@ namespace App\Cache\Redis; use App\Lib\Log\Logger; use Hyperf\Contract\ConfigInterface; -use Hyperf\Di\Annotation\Inject; use Hyperf\Redis\Redis; -use Swoole\Coroutine; +use Exception; use Throwable; abstract class BaseScript @@ -74,7 +73,7 @@ abstract class BaseScript $script = $this->getScriptContent(); // $this->logExecution($keys, $args, true); return $this->execute($script, $keys, $args, $numKeys); - } catch (Throwable $e) { + } catch (Exception|Throwable $e) { $this->logExecution($keys, $args, false, $e); return false; } @@ -82,16 +81,17 @@ abstract class BaseScript /** * @return string + * @throws Exception */ protected function getScriptContent(): string { -// $path = __DIR__.'/Script/'.$this->getName().'.lua'; - $path = __DIR__.'/Lua/'.$this->getName().'.lua'; + $path = __DIR__.'/Script/'.$this->getName().'.lua'; +// $path = __DIR__.'/Lua/'.$this->getName().'.lua'; - if (!file_exists($path)) echo 1; + if (!file_exists($path)) throw new Exception('lua文件不存在'); $content = file_get_contents($path); - if ($content === false) echo 2; + if ($content === false) throw new Exception('lua文件读取失败'); return $content; } @@ -157,7 +157,9 @@ abstract class BaseScript 'keys' => $keys, 'args' => $args, 'success' => $success, - 'error' => $e?->getMessage() + 'error' => $e?->getMessage(), + 'line' => $e?->getLine(), + 'trace' => $e?->getTraceAsString() ]; $logStrategy = match(true) {