1 | <?php |
||
9 | class RedisCache implements CacheInterface |
||
10 | { |
||
11 | const PSR16_RESERVED_CHARACTERS = ['{','}','(',')','/','@',':']; |
||
12 | |||
13 | private $handler = null; |
||
14 | |||
15 | private $serializer = 'PHP'; |
||
16 | |||
17 | /** |
||
18 | * Connect to Redis service |
||
19 | * |
||
20 | * @param Redis $handler Configuration values that has dbIndex name and host's IP address |
||
21 | * |
||
22 | */ |
||
23 | 8 | public function __construct(Redis $handler) |
|
24 | { |
||
25 | 8 | if (defined('Redis::SERIALIZER_IGBINARY') && extension_loaded('igbinary')) { |
|
26 | $handler->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); |
||
27 | } |
||
28 | 8 | $this->handler = $handler; |
|
29 | 8 | } |
|
30 | |||
31 | public function getConnection() |
||
32 | { |
||
33 | return $this->handler; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritDoc} |
||
38 | */ |
||
39 | 2 | public function get($key, $default = null) |
|
40 | { |
||
41 | 2 | $value = $this->handler->get($key); |
|
42 | 2 | return $value ? $value : $default; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * {@inheritDoc} |
||
47 | */ |
||
48 | 2 | public function set($key, $value, $ttl = null) |
|
57 | |||
58 | /** |
||
59 | * {@inheritDoc} |
||
60 | */ |
||
61 | 4 | public function delete($key) |
|
65 | /** |
||
66 | * {@inheritDoc} |
||
67 | */ |
||
68 | 8 | public function clear() |
|
72 | /** |
||
73 | * {@inheritDoc} |
||
74 | */ |
||
75 | 2 | public function getMultiple($keys, $default = null) |
|
83 | /** |
||
84 | * {@inheritDoc} |
||
85 | */ |
||
86 | 2 | public function setMultiple($values, $ttl = null) |
|
101 | /** |
||
102 | * {@inheritDoc} |
||
103 | */ |
||
104 | 2 | public function deleteMultiple($keys) |
|
115 | /** |
||
116 | * Increment a value atomically in the cache by its step value, which defaults to 1 |
||
117 | * |
||
118 | * @param string $key The cache item key |
||
119 | * @param integer $step The value to increment by, defaulting to 1 |
||
120 | * |
||
121 | * @return int|bool The new value on success and false on failure |
||
122 | */ |
||
123 | 2 | public function increment($key, $step = 1) |
|
127 | /** |
||
128 | * Decrement a value atomically in the cache by its step value, which defaults to 1 |
||
129 | * |
||
130 | * @param string $key The cache item key |
||
131 | * @param integer $step The value to decrement by, defaulting to 1 |
||
132 | * |
||
133 | * @return int|bool The new value on success and false on failure |
||
134 | */ |
||
135 | 2 | public function decrement($key, $step = 1) |
|
139 | |||
140 | |||
141 | |||
142 | |||
143 | /** |
||
144 | * {@inheritDoc} |
||
145 | */ |
||
146 | public function has($key) |
||
151 | |||
152 | 2 | private function checkReservedCharacters($key) |
|
166 | } |
||
167 |
This checks looks for cases where a variable has been assigned to itself.
This assignement can be removed without consequences.