This commit is contained in:
2022-07-10 00:15:37 +08:00
parent e54ac1ed39
commit 983722d22f
2 changed files with 1 additions and 51 deletions
-49
View File
@@ -39,9 +39,6 @@ class Helper implements StopHeartbeatCheck
private int $_timer = -1; private int $_timer = -1;
private int $_last = 0;
/** /**
* @param array $config * @param array $config
@@ -59,53 +56,11 @@ class Helper implements StopHeartbeatCheck
} }
public function init()
{
$this->heartbeat_check();
}
/**
*
*/
public function heartbeat_check(): void
{
if ($this->_timer === -1) {
$this->_timer = Timer::tick(1000, fn() => $this->waite());
}
}
/**
* @throws Exception
*/
private function waite(): void
{
try {
if ($this->_timer === -1) {
Kiri::getDi()->get(Logger::class)->critical('timer end');
$this->stopHeartbeatCheck();
}
if (time() - $this->_last > intval($this->pool['tick'] ?? 60)) {
$this->stopHeartbeatCheck();
$this->pdo = null;
}
} catch (\Throwable $throwable) {
error($throwable);
}
}
/** /**
* clear client heartbeat * clear client heartbeat
*/ */
public function stopHeartbeatCheck(): void public function stopHeartbeatCheck(): void
{ {
if ($this->_timer > -1) {
Timer::clear($this->_timer);
}
$this->_timer = -1; $this->_timer = -1;
} }
@@ -132,10 +87,6 @@ class Helper implements StopHeartbeatCheck
*/ */
public function _pdo(): \Redis public function _pdo(): \Redis
{ {
if ($this->_timer === -1) {
$this->heartbeat_check();
}
$this->_last = time();
if (!($this->pdo instanceof \Redis) || !$this->pdo->ping('isOk')) { if (!($this->pdo instanceof \Redis) || !$this->pdo->ping('isOk')) {
$this->pdo = $this->newClient(); $this->pdo = $this->newClient();
} }
+1 -2
View File
@@ -58,7 +58,7 @@ class Redis extends Component
* @throws ConfigException * @throws ConfigException
* @throws Exception * @throws Exception
*/ */
public function init() public function init(): void
{ {
$config = $this->get_config(); $config = $this->get_config();
@@ -78,7 +78,6 @@ class Redis extends Component
*/ */
public function __call($name, $arguments): mixed public function __call($name, $arguments): mixed
{ {
$time = microtime(true);
if (method_exists($this, $name)) { if (method_exists($this, $name)) {
$data = $this->{$name}(...$arguments); $data = $this->{$name}(...$arguments);
} else { } else {