变更
This commit is contained in:
@@ -96,7 +96,11 @@ class Connection extends Component
|
||||
*/
|
||||
public function get(mixed $config, bool $isMaster = false): ?\PDO
|
||||
{
|
||||
return $this->pool->get($config['cds'] . ($isMaster ? 'master' : 'slave'), $this->generate($config));
|
||||
$name = $config['cds'] . ($isMaster ? 'master' : 'slave');
|
||||
if (!$this->pool->hasChannel($name, $config['pool']['max'])) {
|
||||
$this->pool->initConnections($name, $config['pool']['max']);
|
||||
}
|
||||
return $this->pool->get($name, $this->generate($config));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ class Pool extends Component
|
||||
public function channel($name): PoolQueue
|
||||
{
|
||||
$channel = static::$_connections[$name] ?? null;
|
||||
if (!($channel instanceof PoolQueue) ) {
|
||||
if (!($channel instanceof PoolQueue)) {
|
||||
throw new Exception('Channel is not exists.');
|
||||
}
|
||||
if ($channel->isClose()) {
|
||||
@@ -139,6 +139,19 @@ class Pool extends Component
|
||||
}
|
||||
|
||||
|
||||
public function hasChannel($name, $max): bool
|
||||
{
|
||||
$channel = static::$_connections[$name] ?? null;
|
||||
if (!($channel instanceof PoolQueue)) {
|
||||
return false;
|
||||
}
|
||||
if ($channel->isClose()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $callback
|
||||
|
||||
Reference in New Issue
Block a user