qqq
This commit is contained in:
@@ -10,6 +10,7 @@ declare(strict_types=1);
|
|||||||
namespace Kiri\Abstracts;
|
namespace Kiri\Abstracts;
|
||||||
|
|
||||||
|
|
||||||
|
use Database\DatabasesProviders;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri;
|
use Kiri;
|
||||||
use Kiri\Di\LocalService;
|
use Kiri\Di\LocalService;
|
||||||
@@ -22,6 +23,7 @@ use Kiri\Events\EventProvider;
|
|||||||
/**
|
/**
|
||||||
* Class BaseApplication
|
* Class BaseApplication
|
||||||
* @package Kiri\Base
|
* @package Kiri\Base
|
||||||
|
* @property DatabasesProviders $connections
|
||||||
*/
|
*/
|
||||||
abstract class BaseApplication extends Component
|
abstract class BaseApplication extends Component
|
||||||
{
|
{
|
||||||
@@ -32,9 +34,6 @@ abstract class BaseApplication extends Component
|
|||||||
*/
|
*/
|
||||||
public string $storage = APP_PATH . 'storage';
|
public string $storage = APP_PATH . 'storage';
|
||||||
|
|
||||||
public string $envPath = APP_PATH . '.env';
|
|
||||||
|
|
||||||
|
|
||||||
public LocalService $localService;
|
public LocalService $localService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace Kiri;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri;
|
use Kiri;
|
||||||
use Kiri\Abstracts\{BaseApplication, Config, Kernel};
|
use Kiri\Abstracts\{BaseApplication, Kernel};
|
||||||
use Kiri\Di\LocalService;
|
use Kiri\Di\LocalService;
|
||||||
use Kiri\Di\Scanner;
|
use Kiri\Di\Scanner;
|
||||||
use Kiri\Error\ErrorHandler;
|
use Kiri\Error\ErrorHandler;
|
||||||
@@ -31,8 +31,6 @@ use Symfony\Component\Console\{Application as ConsoleApplication,
|
|||||||
* Class Init
|
* Class Init
|
||||||
*
|
*
|
||||||
* @package Kiri
|
* @package Kiri
|
||||||
*
|
|
||||||
* @property-read Config $config
|
|
||||||
*/
|
*/
|
||||||
class Application extends BaseApplication
|
class Application extends BaseApplication
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class Pool extends Component
|
|||||||
* @param int $max
|
* @param int $max
|
||||||
* @param \Closure $closure
|
* @param \Closure $closure
|
||||||
*/
|
*/
|
||||||
public function initConnections($name, int $max, \Closure $closure): void
|
public function created($name, int $max, \Closure $closure): void
|
||||||
{
|
{
|
||||||
if (!isset($this->_connections[$name])) {
|
if (!isset($this->_connections[$name])) {
|
||||||
$this->_connections[$name] = new PoolItem($max, $closure);
|
$this->_connections[$name] = new PoolItem($max, $closure);
|
||||||
@@ -113,12 +113,13 @@ class Pool extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function hasChannel($name): bool
|
public function hasChannel($name): bool
|
||||||
{
|
{
|
||||||
if (!isset($this->_connections[$name])) {
|
return isset($this->_connections[$name]) && $this->_connections[$name] instanceof PoolItem;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -66,9 +66,9 @@ class PoolItem
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function size(): bool
|
public function size(): int
|
||||||
{
|
{
|
||||||
return $this->_items->length();
|
return $this->_items->length();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class Redis extends Component
|
|||||||
|
|
||||||
$length = \config('cache.redis.pool.max', 10);
|
$length = \config('cache.redis.pool.max', 10);
|
||||||
on(OnWorkerExit::class, [$this, 'destroy']);
|
on(OnWorkerExit::class, [$this, 'destroy']);
|
||||||
Kiri::getPool()->initConnections($config['host'], $length, static function () use ($config) {
|
Kiri::getPool()->created($config['host'], $length, static function () use ($config) {
|
||||||
$redis = new \Redis();
|
$redis = new \Redis();
|
||||||
if (!$redis->connect($config['host'], $config['port'], $config['timeout'])) {
|
if (!$redis->connect($config['host'], $config['port'], $config['timeout'])) {
|
||||||
throw new RedisConnectException(sprintf('The Redis Connect %s::%d Fail.', $config['host'], $config['port']));
|
throw new RedisConnectException(sprintf('The Redis Connect %s::%d Fail.', $config['host'], $config['port']));
|
||||||
|
|||||||
Reference in New Issue
Block a user