RedisCache   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 9 2
A __construct() 0 4 1
A set() 0 3 1
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