Total Complexity | 7 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | final class RedisStorage implements Storage |
||
11 | { |
||
12 | private $client; |
||
13 | private $prefix; |
||
14 | |||
15 | public function __construct(ClientInterface $client, string $prefix = '') |
||
16 | { |
||
17 | $this->client = $client; |
||
18 | $this->prefix = $prefix; |
||
19 | } |
||
20 | |||
21 | public function has(string $key): bool |
||
22 | { |
||
23 | $storageKey = $this->storageKey($key); |
||
24 | |||
25 | return (bool) $this->client->exists($storageKey); |
||
26 | } |
||
27 | |||
28 | public function get(string $key): Key |
||
29 | { |
||
30 | $storageKey = $this->storageKey($key); |
||
31 | |||
32 | if (null === $identity = $this->client->get($storageKey)) { |
||
33 | throw new KeyNotFound(); |
||
34 | } |
||
35 | |||
36 | return new Key($key, $identity, $this->client->ttl($storageKey)); |
||
37 | } |
||
38 | |||
39 | public function add(Key $key): void |
||
40 | { |
||
41 | $storageKey = $this->storageKey((string) $key); |
||
42 | |||
43 | $this->client->setex($storageKey, $key->ttl(), $key->identity()); |
||
44 | } |
||
45 | |||
46 | public function remove(string $key): void |
||
51 | } |
||
52 | |||
53 | private function storageKey(string $key): string |
||
56 | } |
||
57 | } |
||
58 |