1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Manage Cache by Redis |
5
|
|
|
* |
6
|
|
|
* @category lib |
7
|
|
|
* @package lib\Cache |
8
|
|
|
* @author Judicaël Paquet <[email protected]> |
9
|
|
|
* @copyright Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93) |
10
|
|
|
* @license https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël |
11
|
|
|
* @version Release: 1.0.0 |
12
|
|
|
* @filesource https://github.com/las93/venus2 |
13
|
|
|
* @link https://github.com/las93 |
14
|
|
|
* @since 1.0 |
15
|
|
|
*/ |
16
|
|
|
namespace Venus\lib\Cache; |
17
|
|
|
|
18
|
|
|
use \Redis as RealRedis; |
19
|
|
|
use \Venus\lib\Cache\CacheInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This class manage the Cache by Redis |
23
|
|
|
* |
24
|
|
|
* @category lib |
25
|
|
|
* @package lib\Cache |
26
|
|
|
* @author Judicaël Paquet <[email protected]> |
27
|
|
|
* @copyright Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93) |
28
|
|
|
* @license https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël |
29
|
|
|
* @version Release: 1.0.0 |
30
|
|
|
* @filesource https://github.com/las93/venus2 |
31
|
|
|
* @link https://github.com/las93 |
32
|
|
|
* @since 1.0 |
33
|
|
|
*/ |
34
|
|
|
class Redis extends RealRedis implements CacheInterface |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* constructor with the connection to Redis |
38
|
|
|
* |
39
|
|
|
* @access public |
40
|
|
|
* @param $oConf |
41
|
|
|
* @throws \Exception |
42
|
|
|
* @internal param string $sName name of the session |
43
|
|
|
* @internal param int $iFlags flags |
44
|
|
|
* @internal param int $iTimeout expiration of cache |
45
|
|
|
*/ |
46
|
|
|
public function __construct($oConf) |
47
|
|
|
{ |
48
|
|
|
if (!$this->connect($oConf->host, $oConf->port)) { |
49
|
|
|
|
50
|
|
|
throw new \Exception('Redis server unavailable'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// Select the REDIS db index |
54
|
|
|
$this->select($oConf->index); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* get a value |
59
|
|
|
* |
60
|
|
|
* @access public |
61
|
|
|
* @param string $sName name of the session |
62
|
|
|
* @param int $iFlags flags |
63
|
|
|
* @param int $iTimeout expiration of cache |
64
|
|
|
* @return mixed |
65
|
|
|
*/ |
66
|
|
|
public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
67
|
|
|
{ |
68
|
|
|
return parent::get($sName); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* set a value |
73
|
|
|
* |
74
|
|
|
* @access public |
75
|
|
|
* @param string $sName name of the session |
76
|
|
|
* @param mixed $mValue value of this sesion var |
77
|
|
|
* @param int $iFlag unused |
78
|
|
|
* @param int $iExpire expiration of cache |
79
|
|
|
* @return \Venus\lib\Cache\Apc |
80
|
|
|
*/ |
81
|
|
|
public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = false) |
82
|
|
|
{ |
83
|
|
|
if ($iExpire === false) { |
84
|
|
|
|
85
|
|
|
return parent::set($sName, $mValue); |
86
|
|
|
} |
87
|
|
|
else { |
88
|
|
|
|
89
|
|
|
return parent::setex($sName, $iExpire, $mValue); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* flush the cache |
95
|
|
|
* |
96
|
|
|
* @access public |
97
|
|
|
* @return mixed |
98
|
|
|
*/ |
99
|
|
|
public function flush() |
100
|
|
|
{ |
101
|
|
|
return false; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* delete a value |
106
|
|
|
* |
107
|
|
|
* @access public |
108
|
|
|
* @param string $sName name of the session |
109
|
|
|
* @return mixed |
110
|
|
|
*/ |
111
|
|
|
public function delete(string $sName) |
112
|
|
|
{ |
113
|
|
|
return $this->del($sName); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* close the redis connecction |
118
|
|
|
* |
119
|
|
|
* @access public |
120
|
|
|
* @return mixed |
121
|
|
|
*/ |
122
|
|
|
public function __sleep() |
123
|
|
|
{ |
124
|
|
|
$this->close(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* add |
129
|
|
|
* |
130
|
|
|
* @access public |
131
|
|
|
* @param string $sName name of the session |
132
|
|
|
* @param mixed $mValue value of this sesion var |
133
|
|
|
* @param int $iFlag unused |
|
|
|
|
134
|
|
|
* @param int $iExpire expiration of cache |
135
|
|
|
* @return mixed |
136
|
|
|
*/ |
137
|
|
|
public function add(string $sName, $mValue, int $iExpire = false) |
138
|
|
|
{ |
139
|
|
|
return $this->set($sName, $mValue, 0, $iExpire); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.