RedisCache::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ICanBoogie\CLDR\Cache;
4
5
use ICanBoogie\CLDR\Cache;
6
use Redis;
7
use RedisCluster;
8
9
use function serialize;
10
use function unserialize;
11
12
/**
13
 * Provides CLDR data from a Redis client.
14
 */
15
final class RedisCache implements Cache
16
{
17
    public const DEFAULT_PREFIX = 'icanboogie-cldr-';
18
19
    public function __construct(
20
        private readonly RedisCluster|Redis $redis,
21
        private readonly string $prefix = self::DEFAULT_PREFIX
22
    ) {
23
    }
24
25
    public function get(string $path): ?array
26
    {
27
        $data = $this->redis->get($this->prefix . $path);
28
29
        if (!$data) {
30
            return null;
31
        }
32
33
        return unserialize($data);
34
    }
35
36
    public function set(string $path, array $data): void
37
    {
38
        $this->redis->set($this->prefix . $path, serialize($data));
39
    }
40
}
41