This commit is contained in:
2021-12-06 15:39:35 +08:00
parent 83962fa3ba
commit 3176443e5c
+12 -5
View File
@@ -2,12 +2,12 @@
namespace Kiri\Cache\Base; namespace Kiri\Cache\Base;
use Exception;
use Kiri\Abstracts\Logger; use Kiri\Abstracts\Logger;
use Kiri\Exception\RedisConnectException; use Kiri\Exception\RedisConnectException;
use Kiri\Kiri; use Kiri\Kiri;
use Kiri\Pool\StopHeartbeatCheck; use Kiri\Pool\StopHeartbeatCheck;
use RedisException; use RedisException;
use Kiri\Context;
use Swoole\Timer; use Swoole\Timer;
@@ -61,8 +61,17 @@ class Redis implements StopHeartbeatCheck
if (env('state', 'start') == 'exit') { if (env('state', 'start') == 'exit') {
return; return;
} }
if ($this->_timer === -1 && Context::inCoroutine()) { if ($this->_timer === -1) {
$this->_timer = Timer::tick(1000, function () { $this->_timer = Timer::tick(1000, fn() => $this->waite());
}
}
/**
* @throws Exception
*/
private function waite(): void
{
try { try {
if (env('state', 'start') == 'exit') { if (env('state', 'start') == 'exit') {
Kiri::getDi()->get(Logger::class)->critical('timer end'); Kiri::getDi()->get(Logger::class)->critical('timer end');
@@ -75,8 +84,6 @@ class Redis implements StopHeartbeatCheck
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
error($throwable); error($throwable);
} }
});
}
} }