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
);
22 private function key($key) {
23 return sprintf("%s:%s", $this->ns
, $key);
26 function get($key, Item
&$item = null, $update = false) {
27 if (!$item = $this->rd
->get($this->key($key))) {
31 if (null === $item->getTTL()) {
34 if ($item->getLTL() >= 0) {
36 $item->setTimestamp();
37 $this->rd
->setex($this->key($key), $item->getTTL() +
60*60*24, $item);
44 function set($key, Item
$item) {
45 if (null === $item->getTTL()) {
46 $this->rd
->set($this->key($key), $item);
48 $this->rd
->setex($this->key($key), $item->getTTL() +
60*60*24, $item);
54 $this->rd
->delete($this->key($key));