Skip to content

Commit

Permalink
Added getConfig for redisPool (#6674)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanyanwow authored Apr 11, 2024
1 parent 5cf164c commit 85bea22
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 32 deletions.
5 changes: 5 additions & 0 deletions src/Pool/RedisPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public function getName(): string
return $this->name;
}

public function getConfig(): array
{
return $this->config;
}

protected function createConnection(): ConnectionInterface
{
return new RedisConnection($this->container, $this, $this->config);
Expand Down
78 changes: 46 additions & 32 deletions tests/RedisConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ public function testRedisConnectionConfig()
], $config);
}

public function testRedisPoolConfig()
{
$pool = $this->getRedisPool();

$config = $pool->getConfig();

$this->assertSame($this->getDefaultPoolConfig(), $config);
}

public function testRedisConnectionReconnect()
{
$pool = $this->getRedisPool();
Expand Down Expand Up @@ -147,43 +156,48 @@ public function testRedisCloseInLowFrequency()
$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(),
],
]));

Expand Down

0 comments on commit 85bea22

Please sign in to comment.