1 | <?php |
||
14 | class UberRedis implements ResourceInterface, UberStorageInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var Redis |
||
18 | */ |
||
19 | private $redis; |
||
20 | |||
21 | /** |
||
22 | * @param Redis $redis |
||
23 | */ |
||
24 | public function __construct(Redis $redis) |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function setConnection($host, $port) |
||
36 | |||
37 | /** |
||
38 | * @return Redis |
||
39 | */ |
||
40 | public function getRedis() |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public function addItem($key, $value, $expiration = null) |
||
49 | { |
||
50 | if ($expiration === null) { |
||
51 | $expiration = 60 * 60 * 24 * 30; // default expires after 30 days |
||
52 | } |
||
53 | $encoded_value = json_encode($value); |
||
54 | |||
55 | return $this->getRedis()->set($key, $encoded_value, $expiration); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function getItem($key) |
||
62 | { |
||
63 | $response = json_decode($this->getRedis()->get($key)); |
||
64 | |||
65 | return $response; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function getAllKeys() |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | public function deleteItem($key) |
||
80 | { |
||
81 | $this->getRedis()->delete($key); |
||
82 | |||
83 | return true; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | public function dropCache() |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function __toString() |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public function isFresh($timestamp) |
||
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | public function getResource() |
||
115 | } |
||
116 |