This commit is contained in:
xl
2023-05-26 09:20:31 +08:00
parent 0f1a55462e
commit d7fd23800b
5 changed files with 14 additions and 16 deletions
+2 -3
View File
@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace Kiri\Abstracts;
use Database\DatabasesProviders;
use Exception;
use Kiri;
use Kiri\Di\LocalService;
@@ -22,6 +23,7 @@ use Kiri\Events\EventProvider;
/**
* Class BaseApplication
* @package Kiri\Base
* @property DatabasesProviders $connections
*/
abstract class BaseApplication extends Component
{
@@ -32,9 +34,6 @@ abstract class BaseApplication extends Component
*/
public string $storage = APP_PATH . 'storage';
public string $envPath = APP_PATH . '.env';
public LocalService $localService;
/**
+1 -3
View File
@@ -12,7 +12,7 @@ namespace Kiri;
use Exception;
use Kiri;
use Kiri\Abstracts\{BaseApplication, Config, Kernel};
use Kiri\Abstracts\{BaseApplication, Kernel};
use Kiri\Di\LocalService;
use Kiri\Di\Scanner;
use Kiri\Error\ErrorHandler;
@@ -31,8 +31,6 @@ use Symfony\Component\Console\{Application as ConsoleApplication,
* Class Init
*
* @package Kiri
*
* @property-read Config $config
*/
class Application extends BaseApplication
{
+6 -5
View File
@@ -90,7 +90,7 @@ class Pool extends Component
* @param int $max
* @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])) {
$this->_connections[$name] = new PoolItem($max, $closure);
@@ -113,12 +113,13 @@ class Pool extends Component
}
/**
* @param $name
* @return bool
*/
public function hasChannel($name): bool
{
if (!isset($this->_connections[$name])) {
return false;
}
return true;
return isset($this->_connections[$name]) && $this->_connections[$name] instanceof PoolItem;
}
+4 -4
View File
@@ -65,10 +65,10 @@ class PoolItem
}
/**
* @return bool
*/
public function size(): bool
/**
* @return int
*/
public function size(): int
{
return $this->_items->length();
}
+1 -1
View File
@@ -68,7 +68,7 @@ class Redis extends Component
$length = \config('cache.redis.pool.max', 10);
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();
if (!$redis->connect($config['host'], $config['port'], $config['timeout'])) {
throw new RedisConnectException(sprintf('The Redis Connect %s::%d Fail.', $config['host'], $config['port']));