改名
This commit is contained in:
+13
-10
@@ -7,6 +7,7 @@ use HttpServer\Http\Context;
|
||||
use PDO;
|
||||
use Exception;
|
||||
use Snowflake\Abstracts\Config;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Swoole\Coroutine;
|
||||
use Snowflake\Abstracts\Pool;
|
||||
use Swoole\Timer;
|
||||
@@ -129,12 +130,12 @@ class Connection extends Pool
|
||||
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param mixed $config
|
||||
* @param bool $isMaster
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getConnection(array $config, $isMaster = false): mixed
|
||||
public function get(mixed $config, $isMaster = false): mixed
|
||||
{
|
||||
$coroutineName = $this->name('mysql', $config['cds'], $isMaster);
|
||||
if (!isset($this->hasCreate[$coroutineName])) {
|
||||
@@ -143,7 +144,7 @@ class Connection extends Pool
|
||||
if (($pdo = Context::getContext($coroutineName)) instanceof PDO) {
|
||||
return $pdo;
|
||||
}
|
||||
$connections = $this->get($coroutineName, $config);
|
||||
$connections = $this->getFromChannel($coroutineName, $config);
|
||||
if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) {
|
||||
$number > 0 && $connections->beginTransaction();
|
||||
}
|
||||
@@ -153,10 +154,11 @@ class Connection extends Pool
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param mixed $config
|
||||
* @return PDO
|
||||
* @throws ComponentException
|
||||
*/
|
||||
public function createClient(string $name, array $config): PDO
|
||||
public function createClient(string $name, mixed $config): PDO
|
||||
{
|
||||
$this->printClients($config['cds'], $name, true);
|
||||
// TODO: Implement createClient() method.
|
||||
@@ -177,11 +179,12 @@ class Connection extends Pool
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $cds
|
||||
* @param $coroutineName
|
||||
* @param false $isBefore
|
||||
*/
|
||||
/**
|
||||
* @param $cds
|
||||
* @param $coroutineName
|
||||
* @param false $isBefore
|
||||
* @throws ComponentException
|
||||
*/
|
||||
public function printClients($cds, $coroutineName, $isBefore = false)
|
||||
{
|
||||
$this->warning(($isBefore ? 'before ' : '') . 'create client[address: ' . $cds . ', ' . env('workerId') . ', coroutine: ' . Coroutine::getCid() . ', has num: ' . $this->size($coroutineName) . ', has create: ' . $this->hasCreate[$coroutineName] . ']');
|
||||
|
||||
+43
-43
@@ -17,54 +17,54 @@ class ObjectPool extends \Snowflake\Abstracts\Pool
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* set pool max length
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->max = 100;
|
||||
}
|
||||
/**
|
||||
* set pool max length
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->max = 100;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param bool $isMaster
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getConnection(array $config, bool $isMaster): mixed
|
||||
{
|
||||
if (is_object($config[0])) {
|
||||
$config[0] = get_class($config[0]) ;
|
||||
}
|
||||
return $this->get(md5($config[0]), $config);
|
||||
}
|
||||
/**
|
||||
* @param array $config
|
||||
* @param bool $isMaster
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get(mixed $config, bool $isMaster = false): mixed
|
||||
{
|
||||
if (is_object($config)) {
|
||||
return $config;
|
||||
}
|
||||
return $this->getFromChannel(md5($config), $config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
public function createClient(string $name, array $config): mixed
|
||||
{
|
||||
// TODO: Implement createClient() method.
|
||||
return Snowflake::createObject(array_shift($config));
|
||||
}
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $config
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
public function createClient(string $name, mixed $config): mixed
|
||||
{
|
||||
// TODO: Implement createClient() method.
|
||||
return Snowflake::createObject(array_shift($config));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param $object
|
||||
*/
|
||||
public function release(string $name, mixed $object)
|
||||
{
|
||||
if (method_exists($object, 'clean')) {
|
||||
$object->clean();
|
||||
}
|
||||
$this->push($name, $object);
|
||||
}
|
||||
/**
|
||||
* @param string $name
|
||||
* @param $object
|
||||
*/
|
||||
public function release(string $name, mixed $object)
|
||||
{
|
||||
if (method_exists($object, 'clean')) {
|
||||
$object->clean();
|
||||
}
|
||||
$this->push($name, $object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,12 @@ class Pool extends \Snowflake\Abstracts\Pool
|
||||
}
|
||||
|
||||
|
||||
public function createClient(string $name, array $config): mixed
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $config
|
||||
* @return mixed
|
||||
*/
|
||||
public function createClient(string $name, mixed $config): mixed
|
||||
{
|
||||
// TODO: Implement createClient() method.
|
||||
return null;
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Snowflake\Pool;
|
||||
use HttpServer\Http\Context;
|
||||
use Redis as SRedis;
|
||||
use RedisException;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\RedisConnectException;
|
||||
use Swoole\Coroutine;
|
||||
use Exception;
|
||||
@@ -33,29 +34,29 @@ class Redis extends Pool
|
||||
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param mixed $config
|
||||
* @param bool $isMaster
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getConnection(array $config, $isMaster = false): mixed
|
||||
public function get(mixed $config, $isMaster = false): mixed
|
||||
{
|
||||
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
|
||||
$coroutineName = $this->name('redis', 'redis:' . $name, $isMaster);
|
||||
if (($redis = Context::getContext($coroutineName)) instanceof \Redis) {
|
||||
return $redis;
|
||||
}
|
||||
return Context::setContext($coroutineName, $this->get($coroutineName, $config));
|
||||
return Context::setContext($coroutineName, $this->getFromChannel($coroutineName, $config));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $config
|
||||
* @param mixed $config
|
||||
* @return SRedis
|
||||
* @throws RedisConnectException
|
||||
* @throws RedisConnectException|ComponentException
|
||||
*/
|
||||
public function createClient(string $name, array $config): SRedis
|
||||
public function createClient(string $name, mixed $config): SRedis
|
||||
{
|
||||
$this->printClients($config['host'], $name, true);
|
||||
$redis = new SRedis();
|
||||
|
||||
Reference in New Issue
Block a user