1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Sunrise CMS - Open source CMS for widespread use. |
4
|
|
|
Copyright (c) 2019 Mykola Burakov ([email protected]) |
5
|
|
|
|
6
|
|
|
See SOURCE.txt for other and additional information. |
7
|
|
|
|
8
|
|
|
This file is part of Sunrise CMS. |
9
|
|
|
|
10
|
|
|
This program is free software: you can redistribute it and/or modify |
11
|
|
|
it under the terms of the GNU General Public License as published by |
12
|
|
|
the Free Software Foundation, either version 3 of the License, or |
13
|
|
|
(at your option) any later version. |
14
|
|
|
|
15
|
|
|
This program is distributed in the hope that it will be useful, |
16
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
GNU General Public License for more details. |
19
|
|
|
|
20
|
|
|
You should have received a copy of the GNU General Public License |
21
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
22
|
|
|
|
23
|
|
|
namespace Sunrise\Engine\Library; |
24
|
|
|
|
25
|
|
|
class RedisCache |
26
|
|
|
{ |
27
|
|
|
public function __construct() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$this->cache = new \Redis(); |
|
|
|
|
30
|
|
|
$this->cache->pconnect('localhost', '6379'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function get($key) |
34
|
|
|
{ |
35
|
|
|
$data = $this->cache->get('snrs_' . $key); |
36
|
|
|
return json_decode($data, true); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function set($key, $value) |
40
|
|
|
{ |
41
|
|
|
$status = $this->cache->set( |
42
|
|
|
'snrs_' . $key, |
43
|
|
|
json_encode($value) |
44
|
|
|
); |
45
|
|
|
if ($status) { |
46
|
|
|
$this->cache->setTimeout( |
47
|
|
|
'snrs_' . $key, |
48
|
|
|
'3600' |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
return $status; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function delete($key) |
55
|
|
|
{ |
56
|
|
|
$this->cache->delete('snrs_' . $key); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|