diff --git a/System/Abstracts/Pool.php b/System/Abstracts/Pool.php index f02a7d50..391d545e 100644 --- a/System/Abstracts/Pool.php +++ b/System/Abstracts/Pool.php @@ -169,6 +169,18 @@ abstract class Pool extends Component } + /** + * @param $cds + * @param $coroutineName + * @param false $isBefore + * @throws Exception + */ + public function releaseClients($cds, $coroutineName) + { + $this->warning('release client[address: ' . $cds . ', ' . env('worker', 0) . ', coroutine: ' . Coroutine::getCid() . ', has num: ' . $this->size($coroutineName) . ']'); + } + + abstract public function createClient(string $name, mixed $config): mixed; diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index 589fed05..bebac1ee 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -195,7 +195,9 @@ class Connection extends Pool return; } - /** @var PDO $client */ + $this->releaseClients('rds', $coroutineName); + + /** @var PDO $client */ $client = Context::getContext($coroutineName); if ($client->inTransaction()) { $client->commit(); @@ -222,7 +224,9 @@ class Connection extends Pool */ public function connection_clear() { - $this->flush(0); + $this->releaseClients('rds', 'rds'); + + $this->flush(0); } diff --git a/System/Pool/Redis.php b/System/Pool/Redis.php index 7c74f26d..83e3e6eb 100644 --- a/System/Pool/Redis.php +++ b/System/Pool/Redis.php @@ -48,13 +48,13 @@ class Redis extends Pool } - /** - * @param string $name - * @param mixed $config - * @return SRedis - * @throws RedisConnectException - * @throws Exception - */ + /** + * @param string $name + * @param mixed $config + * @return SRedis + * @throws RedisConnectException + * @throws Exception + */ public function createClient(string $name, mixed $config): SRedis { $this->printClients($config['host'], $name, true); @@ -89,6 +89,9 @@ class Redis extends Pool if (!Context::hasContext($coroutineName)) { return; } + + $this->releaseClients($config['host'], $coroutineName); + $this->push($coroutineName, Context::getContext($coroutineName)); $this->remove($coroutineName); $this->lastTime = time(); @@ -104,10 +107,13 @@ class Redis extends Pool $name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases']; $coroutineName = $this->name('redis', 'redis:' . $name, $isMaster); if (Context::hasContext($coroutineName)) { - $this->desc($coroutineName); + $this->desc($coroutineName); - $this->remove($coroutineName); + $this->remove($coroutineName); } + + $this->releaseClients($config['host'], $coroutineName); + $this->clean($coroutineName); } @@ -119,12 +125,12 @@ class Redis extends Pool Context::remove($coroutineName); } - /** - * @param string $name - * @param mixed $client - * @return bool - * @throws Exception - */ + /** + * @param string $name + * @param mixed $client + * @return bool + * @throws Exception + */ public function checkCanUse(string $name, mixed $client): bool { try { @@ -136,7 +142,7 @@ class Redis extends Pool $result = true; } } catch (\Throwable $exception) { - $this->addError($exception, 'redis'); + $this->addError($exception, 'redis'); $result = false; } finally { if (!$result) {