|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Koded package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Mihail Binev <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* Please view the LICENSE distributed with this source code |
|
9
|
|
|
* for the full copyright and license information. |
|
10
|
|
|
* |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Koded\Caching\Configuration; |
|
14
|
|
|
|
|
15
|
|
|
use Koded\Caching\CacheException; |
|
16
|
|
|
use Koded\Stdlib\Immutable; |
|
17
|
|
|
use Koded\Stdlib\Interfaces\{Configuration, Serializer}; |
|
18
|
|
|
|
|
19
|
|
|
final class RedisConfiguration extends Immutable implements Configuration |
|
20
|
|
|
{ |
|
21
|
|
|
private $type; |
|
22
|
|
|
|
|
23
|
407 |
|
public function __construct(array $values) |
|
24
|
|
|
{ |
|
25
|
|
|
// @codeCoverageIgnoreStart |
|
26
|
|
|
if (false === class_exists('\Redis', false)) { |
|
27
|
|
|
throw CacheException::generic('Redis extension is not loaded on this machine.'); |
|
28
|
|
|
} |
|
29
|
|
|
// @codeCoverageIgnoreEnd |
|
30
|
|
|
|
|
31
|
|
|
$values += [ |
|
32
|
407 |
|
'serializer' => Serializer::PHP, |
|
33
|
|
|
'binary' => Serializer::PHP, |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
407 |
|
parent::__construct($values); |
|
37
|
|
|
|
|
38
|
407 |
|
switch ($values['serializer']) { |
|
39
|
|
|
case Serializer::PHP: |
|
40
|
199 |
|
$this->type = \Redis::SERIALIZER_PHP; |
|
41
|
199 |
|
break; |
|
42
|
|
|
// @codeCoverageIgnoreStart |
|
43
|
|
|
case Serializer::IGBINARY: |
|
44
|
|
|
$this->type = \Redis::SERIALIZER_IGBINARY; |
|
45
|
|
|
break; |
|
46
|
|
|
// @codeCoverageIgnoreEnd |
|
47
|
|
|
|
|
48
|
|
|
default: |
|
49
|
208 |
|
$this->type = \Redis::SERIALIZER_NONE; |
|
50
|
|
|
} |
|
51
|
407 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* |
|
55
|
|
|
* @return array [ |
|
56
|
|
|
* string $host can be a host, or the path to a unix domain socket |
|
57
|
|
|
* int $port optional, default 6379 |
|
58
|
|
|
* float $timeout value in seconds (optional, default is 0.0 meaning unlimited) |
|
59
|
|
|
* null $reserved should be null if $retry_interval is specified |
|
60
|
|
|
* int $retry_interval retry interval in milliseconds. |
|
61
|
|
|
* ] |
|
62
|
|
|
*/ |
|
63
|
407 |
|
public function getConnectionParams(): array |
|
64
|
|
|
{ |
|
65
|
|
|
return [ |
|
66
|
407 |
|
$this->get('host', '127.0.0.1'), |
|
67
|
407 |
|
$this->get('port', 6379), |
|
68
|
407 |
|
$this->get('timeout', 0.0), |
|
69
|
407 |
|
$this->get('reserved', null), |
|
70
|
407 |
|
$this->get('retry', 0) |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|