Added getConfig for redisPool (#6674)

This commit is contained in:
宣言就是Siam 2024-04-11 18:18:35 +08:00 committed by GitHub
parent c139faa508
commit 2809b6ba5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 55 additions and 32 deletions

View File

@ -1,5 +1,9 @@
# v3.1.18 - TBD
## Added
- [#6674](https://github.com/hyperf/hyperf/pull/6674) Added getConfig for redisPool.
## Fixed
- [#6664](https://github.com/hyperf/hyperf/pull/6664) Fixed bug that `isset` cannot check `null` in `Hyperf\Collection\Collection`.

View File

@ -48,6 +48,11 @@ class RedisPool extends Pool
return $this->name;
}
public function getConfig(): array
{
return $this->config;
}
protected function createConnection(): ConnectionInterface
{
return new RedisConnection($this->container, $this, $this->config);

View File

@ -92,6 +92,15 @@ class RedisConnectionTest extends TestCase
], $config);
}
public function testRedisPoolConfig()
{
$pool = $this->getRedisPool();
$config = $pool->getConfig();
$this->assertSame($this->getDefaultPoolConfig(), $config);
}
public function testRedisConnectionReconnect()
{
$pool = $this->getRedisPool();
@ -147,43 +156,48 @@ class RedisConnectionTest extends TestCase
$connection->release();
}
private function getDefaultPoolConfig()
{
return [
'host' => 'redis',
'auth' => 'redis',
'port' => 16379,
'read_timeout' => 3.0,
'reserved' => null,
'retry_interval' => 5,
'context' => [
'stream' => ['cafile' => 'foo-cafile', 'verify_peer' => true],
],
'pool' => [
'min_connections' => 1,
'max_connections' => 30,
'connect_timeout' => 10.0,
'wait_timeout' => 3.0,
'heartbeat' => -1,
'max_idle_time' => 1,
],
'cluster' => [
'enable' => false,
'name' => null,
'seeds' => [
'127.0.0.1:6379',
],
'context' => [
'stream' => ['cafile' => 'foo-cafile', 'verify_peer' => true],
],
],
'sentinel' => [
'enable' => false,
],
];
}
private function getRedisPool()
{
$container = Mockery::mock(Container::class);
$container->shouldReceive('get')->with(ConfigInterface::class)->andReturn(new Config([
'redis' => [
'default' => [
'host' => 'redis',
'auth' => 'redis',
'port' => 16379,
'read_timeout' => 3.0,
'reserved' => null,
'retry_interval' => 5,
'context' => [
'stream' => ['cafile' => 'foo-cafile', 'verify_peer' => true],
],
'pool' => [
'min_connections' => 1,
'max_connections' => 30,
'connect_timeout' => 10.0,
'wait_timeout' => 3.0,
'heartbeat' => -1,
'max_idle_time' => 1,
],
'cluster' => [
'enable' => false,
'name' => null,
'seeds' => [
'127.0.0.1:6379',
],
'context' => [
'stream' => ['cafile' => 'foo-cafile', 'verify_peer' => true],
],
],
'sentinel' => [
'enable' => false,
],
],
'default' => $this->getDefaultPoolConfig(),
],
]));