This commit is contained in:
2021-07-05 15:49:37 +08:00
parent 74bcdf257e
commit 1a012150ce
5 changed files with 317 additions and 303 deletions
+1 -14
View File
@@ -106,18 +106,6 @@ class ClientsPool extends Component
}
/**
* @param $name
*/
protected function clearCreateLog($name): void
{
if (!isset(static::$hasCreate[$name])) {
return;
}
static::$hasCreate[$name] = 0;
}
/**
* @param Channel $channel
* @param $name
@@ -140,12 +128,11 @@ class ClientsPool extends Component
/**
* @param $driver
* @param $name
* @param false $isMaster
* @param int $max
*/
public function initConnections($driver, $name, bool $isMaster = false, int $max = 60)
public function initConnections($name, bool $isMaster = false, int $max = 60)
{
$name = $this->name($name, $isMaster);
if (isset(static::$_connections[$name]) && static::$_connections[$name] instanceof Channel) {
+19 -3
View File
@@ -113,10 +113,14 @@ class Connection extends Component
if (($pdo = Context::getContext($coroutineName)) instanceof PDO) {
return $pdo;
}
/** @var PDO $connections */
$connections = $this->getPool()->getFromChannel($coroutineName);
if (empty($connections)) {
if (Coroutine::getCid() === -1) {
$connections = $this->createClient($coroutineName, $config);
} else {
/** @var PDO $connections */
$connections = $this->getPool()->getFromChannel($coroutineName);
if (empty($connections)) {
$connections = $this->createClient($coroutineName, $config);
}
}
if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) {
$number > 0 && $connections->beginTransaction();
@@ -125,6 +129,18 @@ class Connection extends Component
}
/**
* @param $name
* @param $isMaster
* @param $max
* @throws Exception
*/
public function initConnections($name, $isMaster, $max)
{
$this->getPool()->initConnections($name, $isMaster, $max);
}
/**
* @param string $name
* @param mixed $config
+12
View File
@@ -126,4 +126,16 @@ class Redis extends Component
}
/**
* @param $name
* @param $isMaster
* @param $max
* @throws Exception
*/
public function initConnections($name, $isMaster, $max)
{
$this->getPool()->initConnections($name, $isMaster, $max);
}
}