改名
This commit is contained in:
+14
-14
@@ -105,7 +105,7 @@ class Connection extends Pool
|
||||
*
|
||||
* db is in transaction
|
||||
*/
|
||||
public function inTransaction($cds)
|
||||
public function inTransaction($cds): bool
|
||||
{
|
||||
$coroutineName = $this->name($cds, true);
|
||||
if (!Context::hasContext('begin_' . $coroutineName)) {
|
||||
@@ -162,7 +162,7 @@ class Connection extends Pool
|
||||
* @param false $isMaster
|
||||
* @return array
|
||||
*/
|
||||
private function getIndex($name, $isMaster = false)
|
||||
private function getIndex($name, $isMaster = false): array
|
||||
{
|
||||
return [Coroutine::getCid(), $this->name($name, $isMaster)];
|
||||
}
|
||||
@@ -197,7 +197,7 @@ class Connection extends Pool
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getConnection(array $config, $isMaster = false)
|
||||
public function getConnection(array $config, $isMaster = false): mixed
|
||||
{
|
||||
$coroutineName = $this->name($config['cds'], $isMaster);
|
||||
if (!isset($this->hasCreate[$coroutineName])) {
|
||||
@@ -222,7 +222,7 @@ class Connection extends Pool
|
||||
* @param $client
|
||||
* @return mixed
|
||||
*/
|
||||
private function saveClient($coroutineName, $client)
|
||||
private function saveClient($coroutineName, $client): mixed
|
||||
{
|
||||
return Context::setContext($coroutineName, $client);
|
||||
}
|
||||
@@ -234,7 +234,7 @@ class Connection extends Pool
|
||||
* @return PDO
|
||||
* @throws Exception
|
||||
*/
|
||||
private function nowClient($coroutineName, $config)
|
||||
private function nowClient($coroutineName, $config): PDO
|
||||
{
|
||||
$client = $this->createConnect($coroutineName, ...$this->parseConfig($config));
|
||||
if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) {
|
||||
@@ -251,7 +251,7 @@ class Connection extends Pool
|
||||
* @param $config
|
||||
* @return array
|
||||
*/
|
||||
private function parseConfig($config)
|
||||
private function parseConfig($config): array
|
||||
{
|
||||
return [$config['cds'], $config['username'], $config['password'], $config['charset'] ?? 'utf8mb4'];
|
||||
}
|
||||
@@ -283,7 +283,7 @@ class Connection extends Pool
|
||||
* @param $coroutineName
|
||||
* @return bool
|
||||
*/
|
||||
private function hasClient($coroutineName)
|
||||
private function hasClient($coroutineName): bool
|
||||
{
|
||||
return Context::hasContext($coroutineName);
|
||||
}
|
||||
@@ -323,19 +323,19 @@ class Connection extends Pool
|
||||
/**
|
||||
* @param $name
|
||||
* @param $time
|
||||
* @param $connect
|
||||
* @param $client
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCanUse($name, $time, $connect)
|
||||
public function checkCanUse($name, $time, $client): bool
|
||||
{
|
||||
try {
|
||||
if ($time + 60 * 10 > time()) {
|
||||
return $result = true;
|
||||
}
|
||||
if (empty($connect) || !($connect instanceof PDO)) {
|
||||
if (empty($client) || !($client instanceof PDO)) {
|
||||
return $result = false;
|
||||
}
|
||||
if (!$connect->getAttribute(PDO::ATTR_SERVER_INFO)) {
|
||||
if (!$client->getAttribute(PDO::ATTR_SERVER_INFO)) {
|
||||
return $result = false;
|
||||
}
|
||||
return $result = true;
|
||||
@@ -358,7 +358,7 @@ class Connection extends Pool
|
||||
* @return PDO
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createConnect($coroutineName, $cds, $username, $password, $charset = 'utf8mb4')
|
||||
public function createConnect($coroutineName, $cds, $username, $password, $charset = 'utf8mb4'): PDO
|
||||
{
|
||||
try {
|
||||
$link = new PDO($cds, $username, $password, [
|
||||
@@ -408,9 +408,9 @@ class Connection extends Pool
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $coroutineName
|
||||
* @param string $coroutineName
|
||||
*/
|
||||
public function desc($coroutineName)
|
||||
public function desc(string $coroutineName)
|
||||
{
|
||||
if (!isset($this->hasCreate[$coroutineName])) {
|
||||
$this->hasCreate[$coroutineName] = 0;
|
||||
|
||||
+3
-11
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace Snowflake\Pool;
|
||||
|
||||
|
||||
use Snowflake\Cache\Memcached;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ class Pool extends \Snowflake\Abstracts\Pool
|
||||
/**
|
||||
* @return Redis
|
||||
*/
|
||||
public function getRedis()
|
||||
#[Pure] public function getRedis(): Redis
|
||||
{
|
||||
return Snowflake::app()->redis_connections;
|
||||
}
|
||||
@@ -29,18 +29,10 @@ class Pool extends \Snowflake\Abstracts\Pool
|
||||
/**
|
||||
* @return Connection
|
||||
*/
|
||||
public function getDb()
|
||||
#[Pure] public function getDb(): Connection
|
||||
{
|
||||
return Snowflake::app()->connections;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Memcached
|
||||
*/
|
||||
public function getMemcached()
|
||||
{
|
||||
return Snowflake::app()->memcached;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-9
@@ -31,10 +31,11 @@ class Redis extends Pool
|
||||
/**
|
||||
* @param array $config
|
||||
* @param bool $isMaster
|
||||
* @return mixed|null
|
||||
* @return mixed
|
||||
* @throws RedisConnectException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getConnection(array $config, $isMaster = false)
|
||||
public function getConnection(array $config, $isMaster = false): mixed
|
||||
{
|
||||
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
|
||||
$coroutineName = $this->name('redis:' . $name, $isMaster);
|
||||
@@ -53,7 +54,7 @@ class Redis extends Pool
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getByChannel($coroutineName, $config)
|
||||
public function getByChannel($coroutineName, $config): mixed
|
||||
{
|
||||
if (!$this->hasItem($coroutineName)) {
|
||||
return $this->saveClient($coroutineName, $this->createConnect($config, $coroutineName));
|
||||
@@ -72,7 +73,7 @@ class Redis extends Pool
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
private function saveClient($coroutineName, $client)
|
||||
private function saveClient($coroutineName, $client): mixed
|
||||
{
|
||||
return Context::setContext($coroutineName, $client);
|
||||
}
|
||||
@@ -84,7 +85,7 @@ class Redis extends Pool
|
||||
* @return SRedis
|
||||
* @throws RedisConnectException
|
||||
*/
|
||||
private function createConnect(array $config, string $coroutineName)
|
||||
private function createConnect(array $config, string $coroutineName): SRedis
|
||||
{
|
||||
$redis = new SRedis();
|
||||
if (!$redis->connect($config['host'], (int)$config['port'], $config['timeout'])) {
|
||||
@@ -139,7 +140,7 @@ class Redis extends Pool
|
||||
/**
|
||||
* @param $coroutineName
|
||||
*/
|
||||
public function remove($coroutineName)
|
||||
public function remove(string $coroutineName)
|
||||
{
|
||||
Context::deleteId($coroutineName);
|
||||
}
|
||||
@@ -148,10 +149,10 @@ class Redis extends Pool
|
||||
* @param $name
|
||||
* @param $time
|
||||
* @param $client
|
||||
* @return bool|mixed
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkCanUse($name, $time, $client)
|
||||
public function checkCanUse(string $name, int $time, mixed $client): bool
|
||||
{
|
||||
try {
|
||||
if ($time + 60 * 10 < time()) {
|
||||
@@ -173,7 +174,7 @@ class Redis extends Pool
|
||||
}
|
||||
}
|
||||
|
||||
public function desc($name)
|
||||
public function desc(string $name)
|
||||
{
|
||||
// TODO: Implement desc() method.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user