From cfd8f6fa9486cbfb507f9a5bc1dce3f4833a325d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 17 Aug 2021 19:01:37 +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 --- System/Cache/Redis.php | 2 +- System/Pool/Connection.php | 5 ++++- System/Pool/Redis.php | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/System/Cache/Redis.php b/System/Cache/Redis.php index 7b4c8190..42d12659 100644 --- a/System/Cache/Redis.php +++ b/System/Cache/Redis.php @@ -126,7 +126,7 @@ SCRIPT; public function destroy() { $connections = Kiri::getDi()->get(PoolRedis::class); - $connections->destroy($this->get_config(), true); + $connections->connection_clear($this->get_config(), true); } /** diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index 923dd1aa..84b8cc95 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -3,12 +3,15 @@ declare(strict_types=1); namespace Kiri\Pool; +use Annotation\Inject; use Closure; use Database\Mysql\PDO; use Exception; use Http\Context\Context; use Kiri\Abstracts\Component; +use Kiri\Events\EventProvider; use Kiri\Kiri; +use Server\Events\OnWorkerExit; use Swoole\Error; use Throwable; @@ -34,7 +37,7 @@ class Connection extends Component $name = $this->name('Mysql:' . $cds, true); $connection = Context::getContext($name); if ($connection instanceof PDO) { - $connection->inTransaction(); + return $connection->inTransaction(); } return false; } diff --git a/System/Pool/Redis.php b/System/Pool/Redis.php index 7f179ea1..f698009f 100644 --- a/System/Pool/Redis.php +++ b/System/Pool/Redis.php @@ -5,16 +5,15 @@ declare(strict_types=1); namespace Kiri\Pool; +use Annotation\Inject; use Closure; use Exception; use Http\Context\Context; use Kiri\Abstracts\Component; +use Kiri\Events\EventProvider; use Kiri\Exception\ConfigException; -use Kiri\Exception\RedisConnectException; use Kiri\Kiri; -use Redis as SRedis; -use Swoole\Coroutine; -use Swoole\Runtime; +use Server\Events\OnWorkerExit; /** * Class RedisClient @@ -90,6 +89,18 @@ class Redis extends Component } + /** + * @param array $config + * @param bool $isMaster + * @throws Exception + */ + public function connection_clear(array $config, bool $isMaster = false) + { + $coroutineName = $this->name('Redis:' . $config['host'], $isMaster); + $this->getPool()->clean($coroutineName); + } + + /** * @return Pool * @throws Exception