Repository navigation
Expand file tree
/
Copy pathRedisPool.php
More file actions
60 lines (48 loc) · 1.46 KB
/
Copy pathRedisPool.php
File metadata and controls
60 lines (48 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Redis\Pool;
use Hyperf\Collection\Arr;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\ConnectionInterface;
use Hyperf\Pool\Pool;
use Hyperf\Redis\Frequency;
use Hyperf\Redis\RedisConnection;
use InvalidArgumentException;
use Psr\Container\ContainerInterface;
use function Hyperf\Support\make;
class RedisPool extends Pool
{
protected array $config;
public function __construct(ContainerInterface $container, protected string $name)
{
$config = $container->get(ConfigInterface::class);
$key = sprintf('redis.%s', $this->name);
if (! $config->has($key)) {
throw new InvalidArgumentException(sprintf('config[%s] is not exist!', $key));
}
$this->config = $config->get($key);
$options = Arr::get($this->config, 'pool', []);
$this->frequency = make(Frequency::class, [$this]);
parent::__construct($container, $options);
}
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);
}
}