feat : common redis cache

This commit is contained in:
2025-09-14 16:07:34 +08:00
parent 0db9995c19
commit cf5d5059d7

View File

@@ -5,9 +5,8 @@ namespace App\Cache\Redis;
use App\Lib\Log\Logger; use App\Lib\Log\Logger;
use Hyperf\Contract\ConfigInterface; use Hyperf\Contract\ConfigInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Redis\Redis; use Hyperf\Redis\Redis;
use Swoole\Coroutine; use Exception;
use Throwable; use Throwable;
abstract class BaseScript abstract class BaseScript
@@ -74,7 +73,7 @@ abstract class BaseScript
$script = $this->getScriptContent(); $script = $this->getScriptContent();
// $this->logExecution($keys, $args, true); // $this->logExecution($keys, $args, true);
return $this->execute($script, $keys, $args, $numKeys); return $this->execute($script, $keys, $args, $numKeys);
} catch (Throwable $e) { } catch (Exception|Throwable $e) {
$this->logExecution($keys, $args, false, $e); $this->logExecution($keys, $args, false, $e);
return false; return false;
} }
@@ -82,16 +81,17 @@ abstract class BaseScript
/** /**
* @return string * @return string
* @throws Exception
*/ */
protected function getScriptContent(): string protected function getScriptContent(): string
{ {
// $path = __DIR__.'/Script/'.$this->getName().'.lua'; $path = __DIR__.'/Script/'.$this->getName().'.lua';
$path = __DIR__.'/Lua/'.$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); $content = file_get_contents($path);
if ($content === false) echo 2; if ($content === false) throw new Exception('lua文件读取失败');
return $content; return $content;
} }
@@ -157,7 +157,9 @@ abstract class BaseScript
'keys' => $keys, 'keys' => $keys,
'args' => $args, 'args' => $args,
'success' => $success, 'success' => $success,
'error' => $e?->getMessage() 'error' => $e?->getMessage(),
'line' => $e?->getLine(),
'trace' => $e?->getTraceAsString()
]; ];
$logStrategy = match(true) { $logStrategy = match(true) {