改名
This commit is contained in:
@@ -6,8 +6,9 @@ namespace Kiri\Pool;
|
|||||||
use Closure;
|
use Closure;
|
||||||
use Database\Mysql\PDO;
|
use Database\Mysql\PDO;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Context;
|
|
||||||
use Kiri\Abstracts\Component;
|
use Kiri\Abstracts\Component;
|
||||||
|
use Kiri\Abstracts\Config;
|
||||||
|
use Kiri\Context;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
use Swoole\Error;
|
use Swoole\Error;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
@@ -92,8 +93,11 @@ class Connection extends Component
|
|||||||
if (($pdo = Context::getContext($coroutineName)) instanceof PDO) {
|
if (($pdo = Context::getContext($coroutineName)) instanceof PDO) {
|
||||||
return $pdo;
|
return $pdo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$minx = Config::get('databases.pool.min', 1);
|
||||||
|
|
||||||
/** @var PDO $connections */
|
/** @var PDO $connections */
|
||||||
$connections = $this->getPool()->get($coroutineName, $this->create($coroutineName, $config));
|
$connections = $this->getPool()->get($coroutineName, $this->create($coroutineName, $config), $minx);
|
||||||
if (Context::hasContext('begin_' . $coroutineName)) {
|
if (Context::hasContext('begin_' . $coroutineName)) {
|
||||||
$connections->beginTransaction();
|
$connections->beginTransaction();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,14 +115,16 @@ class Pool extends Component
|
|||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @param $callback
|
* @param $callback
|
||||||
|
* @param $minx
|
||||||
* @return array
|
* @return array
|
||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function get($name, $callback): mixed
|
public function get($name, $callback, $minx): mixed
|
||||||
{
|
{
|
||||||
$channel = $this->getChannel($name);
|
$channel = $this->getChannel($name);
|
||||||
if (!$channel->isEmpty()) {
|
if (!$channel->isEmpty()) {
|
||||||
return $this->maxIdleQuantity($channel);
|
return $this->maxIdleQuantity($channel, $minx);
|
||||||
}
|
}
|
||||||
return $callback();
|
return $callback();
|
||||||
}
|
}
|
||||||
@@ -130,14 +132,13 @@ class Pool extends Component
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $channel
|
* @param $channel
|
||||||
|
* @param $minx
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws ConfigException
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function maxIdleQuantity($channel): mixed
|
protected function maxIdleQuantity($channel, $minx): mixed
|
||||||
{
|
{
|
||||||
$connection = $channel->pop();
|
$connection = $channel->pop();
|
||||||
$minx = Config::get('databases.pool.min', 1);
|
|
||||||
if ($channel->length() > $minx) {
|
if ($channel->length() > $minx) {
|
||||||
$this->pop($channel, $minx);
|
$this->pop($channel, $minx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,12 @@ declare(strict_types=1);
|
|||||||
namespace Kiri\Pool;
|
namespace Kiri\Pool;
|
||||||
|
|
||||||
|
|
||||||
use Annotation\Inject;
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Context;
|
|
||||||
use Kiri\Abstracts\Component;
|
use Kiri\Abstracts\Component;
|
||||||
use Kiri\Events\EventProvider;
|
use Kiri\Context;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
use Server\Events\OnWorkerExit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RedisClient
|
* Class RedisClient
|
||||||
@@ -37,7 +34,10 @@ class Redis extends Component
|
|||||||
if (Context::hasContext($coroutineName)) {
|
if (Context::hasContext($coroutineName)) {
|
||||||
return Context::getContext($coroutineName);
|
return Context::getContext($coroutineName);
|
||||||
}
|
}
|
||||||
$clients = $this->getPool()->get($coroutineName, $this->create($coroutineName, $config));
|
|
||||||
|
$pool = $config['pool'] ?? ['min' => 1, 'max' => 100];
|
||||||
|
|
||||||
|
$clients = $this->getPool()->get($coroutineName, $this->create($coroutineName, $config), $pool['min'] ?? 1);
|
||||||
return Context::setContext($coroutineName, $clients);
|
return Context::setContext($coroutineName, $clients);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user