| Total Complexity | 6 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class RedisStorage implements Storage |
||
| 11 | { |
||
| 12 | private $client; |
||
| 13 | |||
| 14 | public function __construct(Client $client) |
||
| 15 | { |
||
| 16 | $this->client = $client; |
||
| 17 | } |
||
| 18 | |||
| 19 | public function has(string $key): bool |
||
| 20 | { |
||
| 21 | return (bool) $this->client->exists($key); |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @throws KeyNotFoundException |
||
| 26 | */ |
||
| 27 | public function get(string $key): Key |
||
| 28 | { |
||
| 29 | if (null === $username = $this->client->get($key)) { |
||
| 30 | throw new KeyNotFoundException(); |
||
| 31 | } |
||
| 32 | |||
| 33 | return new Key($key, $username, $this->client->ttl($key)); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function add(Key $key): void |
||
| 37 | { |
||
| 38 | $this->client->setex((string) $key, $key->ttl(), $key->username()); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function remove(string $key): void |
||
| 44 | } |
||
| 45 | } |
||
| 46 |