From b3e06a680a07e0799651b9d44b13b5716f8e465d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Mon, 6 Dec 2021 15:47:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/Cache/Base/Redis.php | 36 +++++++++++++++++++++----------- kiri-engine/Cache/Redis.php | 2 +- kiri-engine/Pool/Redis.php | 6 +----- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/kiri-engine/Cache/Base/Redis.php b/kiri-engine/Cache/Base/Redis.php index 8681b511..a3abd50f 100644 --- a/kiri-engine/Cache/Base/Redis.php +++ b/kiri-engine/Cache/Base/Redis.php @@ -22,9 +22,21 @@ class Redis implements StopHeartbeatCheck private ?\Redis $pdo = null; + public string $host; - private int $_transaction = 0; + public int $port; + public int $database = 0; + + public string $auth = ''; + + public string $prefix = ''; + + public int $timeout = 30; + + public int $read_timeout = 30; + + public array $pool = []; private int $_timer = -1; @@ -32,18 +44,18 @@ class Redis implements StopHeartbeatCheck /** - * @param string $host - * @param int $port - * @param int $database - * @param string $auth - * @param string $prefix - * @param int $timeout - * @param int $read_timeout + * @param array $config */ - public function __construct(public string $host, public int $port, public int $database = 0, - public string $auth = '', public string $prefix = '', public int $timeout = 30, - public int $read_timeout = 30) + public function __construct(array $config) { + $this->host = $config['host']; + $this->port = $config['port']; + $this->database = $config['database']; + $this->auth = $config['auth']; + $this->prefix = $config['prefix']; + $this->timeout = $config['timeout']; + $this->read_timeout = $config['read_timeout']; + $this->pool = $config['pool']; } @@ -77,7 +89,7 @@ class Redis implements StopHeartbeatCheck Kiri::getDi()->get(Logger::class)->critical('timer end'); $this->stopHeartbeatCheck(); } - if (time() - $this->_last > 10 * 60) { + if (time() - $this->_last > intval($this->pool['tick'] ?? 60)) { $this->stopHeartbeatCheck(); $this->pdo = null; } diff --git a/kiri-engine/Cache/Redis.php b/kiri-engine/Cache/Redis.php index a1973e93..4541dbbe 100644 --- a/kiri-engine/Cache/Redis.php +++ b/kiri-engine/Cache/Redis.php @@ -45,7 +45,7 @@ class Redis extends Component $config = $this->get_config(); - $length = Config::get('connections.pool.max', 10); + $length = Config::get('cache.redis.pool.max', 10); $this->eventProvider->on(OnWorkerExit::class, [$this, 'destroy'], 0); diff --git a/kiri-engine/Pool/Redis.php b/kiri-engine/Pool/Redis.php index e37a788a..b4340e2a 100644 --- a/kiri-engine/Pool/Redis.php +++ b/kiri-engine/Pool/Redis.php @@ -50,11 +50,7 @@ class Redis extends Component public function create(string $name, mixed $config): Closure { return static function () use ($name, $config) { - return Kiri::getDi()->create(\Kiri\Cache\Base\Redis::class, [ - $config['host'], (int)$config['port'], $config['databases'] ?? 0, - $config['auth'], $config['prefix'] ?? '', $config['timeout'] ?? 30, - $config['read_timeout'] ?? 30 - ]); + return Kiri::getDi()->create(\Kiri\Cache\Base\Redis::class, $config); }; }