This commit is contained in:
as2252258@163.com
2021-04-23 03:41:12 +08:00
parent 1edd8c5429
commit 176d6256d7
3 changed files with 40 additions and 18 deletions
+12
View File
@@ -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; abstract public function createClient(string $name, mixed $config): mixed;
+6 -2
View File
@@ -195,7 +195,9 @@ class Connection extends Pool
return; return;
} }
/** @var PDO $client */ $this->releaseClients('rds', $coroutineName);
/** @var PDO $client */
$client = Context::getContext($coroutineName); $client = Context::getContext($coroutineName);
if ($client->inTransaction()) { if ($client->inTransaction()) {
$client->commit(); $client->commit();
@@ -222,7 +224,9 @@ class Connection extends Pool
*/ */
public function connection_clear() public function connection_clear()
{ {
$this->flush(0); $this->releaseClients('rds', 'rds');
$this->flush(0);
} }
+22 -16
View File
@@ -48,13 +48,13 @@ class Redis extends Pool
} }
/** /**
* @param string $name * @param string $name
* @param mixed $config * @param mixed $config
* @return SRedis * @return SRedis
* @throws RedisConnectException * @throws RedisConnectException
* @throws Exception * @throws Exception
*/ */
public function createClient(string $name, mixed $config): SRedis public function createClient(string $name, mixed $config): SRedis
{ {
$this->printClients($config['host'], $name, true); $this->printClients($config['host'], $name, true);
@@ -89,6 +89,9 @@ class Redis extends Pool
if (!Context::hasContext($coroutineName)) { if (!Context::hasContext($coroutineName)) {
return; return;
} }
$this->releaseClients($config['host'], $coroutineName);
$this->push($coroutineName, Context::getContext($coroutineName)); $this->push($coroutineName, Context::getContext($coroutineName));
$this->remove($coroutineName); $this->remove($coroutineName);
$this->lastTime = time(); $this->lastTime = time();
@@ -104,10 +107,13 @@ class Redis extends Pool
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases']; $name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
$coroutineName = $this->name('redis', 'redis:' . $name, $isMaster); $coroutineName = $this->name('redis', 'redis:' . $name, $isMaster);
if (Context::hasContext($coroutineName)) { if (Context::hasContext($coroutineName)) {
$this->desc($coroutineName); $this->desc($coroutineName);
$this->remove($coroutineName); $this->remove($coroutineName);
} }
$this->releaseClients($config['host'], $coroutineName);
$this->clean($coroutineName); $this->clean($coroutineName);
} }
@@ -119,12 +125,12 @@ class Redis extends Pool
Context::remove($coroutineName); Context::remove($coroutineName);
} }
/** /**
* @param string $name * @param string $name
* @param mixed $client * @param mixed $client
* @return bool * @return bool
* @throws Exception * @throws Exception
*/ */
public function checkCanUse(string $name, mixed $client): bool public function checkCanUse(string $name, mixed $client): bool
{ {
try { try {
@@ -136,7 +142,7 @@ class Redis extends Pool
$result = true; $result = true;
} }
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$this->addError($exception, 'redis'); $this->addError($exception, 'redis');
$result = false; $result = false;
} finally { } finally {
if (!$result) { if (!$result) {