改名
This commit is contained in:
@@ -174,6 +174,9 @@ abstract class Pool extends Component
|
|||||||
{
|
{
|
||||||
if (!isset(static::$_items[$name])) {
|
if (!isset(static::$_items[$name])) {
|
||||||
static::$_items[$name] = new Channel(Config::get('databases.pool.max', 10));
|
static::$_items[$name] = new Channel(Config::get('databases.pool.max', 10));
|
||||||
|
if ($this->creates === -1) {
|
||||||
|
$this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection'], $name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return static::$_items[$name];
|
return static::$_items[$name];
|
||||||
}
|
}
|
||||||
@@ -250,19 +253,6 @@ abstract class Pool extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function canCreate(string $name): bool
|
|
||||||
{
|
|
||||||
if (!isset(static::$hasCreate[$name])) {
|
|
||||||
static::$hasCreate[$name] = 0;
|
|
||||||
}
|
|
||||||
return static::$hasCreate[$name] < $this->max;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ class Redis extends Component
|
|||||||
$config = $this->get_config();
|
$config = $this->get_config();
|
||||||
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
|
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
|
||||||
|
|
||||||
$length = env('REDIS.POOL_LENGTH', 100);
|
$length = (int)env('REDIS.POOL_LENGTH', 100);
|
||||||
|
|
||||||
$connections->initConnections('redis', 'redis:' . $name, true, $length);
|
$connections->initConnections('redis', $name, true, $length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
-22
@@ -9,6 +9,7 @@ use Exception;
|
|||||||
use HttpServer\Http\Context;
|
use HttpServer\Http\Context;
|
||||||
use Redis as SRedis;
|
use Redis as SRedis;
|
||||||
use Snowflake\Abstracts\Pool;
|
use Snowflake\Abstracts\Pool;
|
||||||
|
use Snowflake\Exception\ConfigException;
|
||||||
use Snowflake\Exception\RedisConnectException;
|
use Snowflake\Exception\RedisConnectException;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Swoole\Runtime;
|
use Swoole\Runtime;
|
||||||
@@ -32,19 +33,6 @@ class Redis extends Pool
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function canCreate(string $name): bool
|
|
||||||
{
|
|
||||||
if (!isset(static::$hasCreate[$name])) {
|
|
||||||
static::$hasCreate[$name] = 0;
|
|
||||||
}
|
|
||||||
return static::$hasCreate[$name] >= $this->max;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $config
|
* @param mixed $config
|
||||||
* @param bool $isMaster
|
* @param bool $isMaster
|
||||||
@@ -53,9 +41,9 @@ class Redis extends Pool
|
|||||||
*/
|
*/
|
||||||
public function get(mixed $config, bool $isMaster = false): mixed
|
public function get(mixed $config, bool $isMaster = false): mixed
|
||||||
{
|
{
|
||||||
$coroutineName = $this->name('redis', 'redis:' . $config['host'], $isMaster);
|
$coroutineName = $this->name('redis', $config['host'], $isMaster);
|
||||||
if (!Context::hasContext($coroutineName)) {
|
if (!Context::hasContext($coroutineName)) {
|
||||||
return Context::setContext($coroutineName, $this->getFromChannel($coroutineName, $config));
|
return Context::setContext($coroutineName, $this->getFromChannel($coroutineName, $config));
|
||||||
}
|
}
|
||||||
return Context::getContext($coroutineName);
|
return Context::getContext($coroutineName);
|
||||||
}
|
}
|
||||||
@@ -96,17 +84,16 @@ class Redis extends Pool
|
|||||||
/**
|
/**
|
||||||
* @param array $config
|
* @param array $config
|
||||||
* @param bool $isMaster
|
* @param bool $isMaster
|
||||||
|
* @throws ConfigException
|
||||||
*/
|
*/
|
||||||
public function release(array $config, bool $isMaster = false)
|
public function release(array $config, bool $isMaster = false)
|
||||||
{
|
{
|
||||||
$coroutineName = $this->name('redis', 'redis:' . $config['host'], $isMaster);
|
$coroutineName = $this->name('redis', $config['host'], $isMaster);
|
||||||
if (!Context::hasContext($coroutineName)) {
|
if (!Context::hasContext($coroutineName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->push($coroutineName, Context::getContext($coroutineName));
|
$this->push($coroutineName, Context::getContext($coroutineName));
|
||||||
Context::remove($coroutineName);
|
|
||||||
$this->lastTime = time();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,12 +103,12 @@ class Redis extends Pool
|
|||||||
*/
|
*/
|
||||||
public function destroy(array $config, bool $isMaster = false)
|
public function destroy(array $config, bool $isMaster = false)
|
||||||
{
|
{
|
||||||
$coroutineName = $this->name('redis', 'redis:' . $config['host'], $isMaster);
|
$coroutineName = $this->name('redis', $config['host'], $isMaster);
|
||||||
if (Context::hasContext($coroutineName)) {
|
if (Context::hasContext($coroutineName)) {
|
||||||
$this->decrement($coroutineName);
|
$this->decrement($coroutineName);
|
||||||
}
|
}
|
||||||
Context::remove($coroutineName);
|
Context::remove($coroutineName);
|
||||||
$this->flush(0);
|
$this->flush(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,5 +137,4 @@ class Redis extends Pool
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user