3 namespace app\Github\Storage
;
5 use app\Github\Storage
;
7 class Redis
implements Storage
12 function __construct($ns = "github", \Redis
$rd = null) {
16 $rd->open("localhost");
17 $rd->setOption(\Redis
::OPT_SERIALIZER
, \Redis
::SERIALIZER_PHP
);
18 $rd->setOption(\Redis
::OPT_PREFIX
, "$ns:");
23 function get($key, Item
&$item = null, $update = false) {
24 if (!$item = $this->rd
->get($key)) {
28 if (null === $item->getTTL()) {
31 if ($item->getLTL() >= 0) {
33 $item->setTimestamp();
34 $this->rd
->setex($key, $item->getTTL() +
60*60*24, $item);
41 function set($key, Item
$item) {
42 if (null === $item->getTTL()) {
43 $this->rd
->set($key, $item);
45 $this->rd
->setex($key, $item->getTTL() +
60*60*24, $item);
51 $this->rd
->delete($key);