This commit is contained in:
2025-12-31 00:19:31 +08:00
parent 87e7535f27
commit baea90e9e5
6 changed files with 763 additions and 811 deletions
+17 -8
View File
@@ -103,13 +103,13 @@ class Redis
public function lock($key, int $timeout = 5): bool|int
{
$script = <<<SCRIPT
local _nx = redis.call('setnx',KEYS[1], ARGV[1])
if (_nx ~= 0) then
redis.call('expire',KEYS[1], ARGV[1])
return 1
end
return 0
SCRIPT;
local _nx = redis.call('setnx',KEYS[1], ARGV[1])
if (_nx ~= 0) then
redis.call('expire',KEYS[1], ARGV[1])
return 1
end
return 0
SCRIPT;
return $this->eval($script, ['{lock}:' . $key, $timeout], 1);
}
@@ -147,7 +147,7 @@ SCRIPT;
try {
return $client->{$name}(...$arguments);
} catch (\Throwable $throwable) {
return trigger_print_error(throwable($throwable));
return $this->getLogger()->json_log($throwable, [], false);
} finally {
if ($client->ping('h') == 'h') {
$this->pool()->push($this->getName(), $client);
@@ -156,6 +156,15 @@ SCRIPT;
}
/**
* @return Kiri\Error\StdoutLogger
*/
protected function getLogger(): Kiri\Error\StdoutLogger
{
return Kiri::getLogger();
}
/**
* @return \Redis
* @throws