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, &$val = null, &$ltl = null, $update = false) {
27 if (!$item = $this->rd
->get($this->key($key))) {
28 header("Cache-Item: ".serialize($item), false);
40 $ltl = $ttl - ($now - $set);
44 $this->rd
->setex($this->key($key), $ttl +
60*60*24, $item);
51 function set($key, $val, $ttl = null) {
52 $item = new Redis\
Item([
55 "time" => isset($ttl) ?
time() : null
58 $this->rd
->set($this->key($key), $item);
60 $this->rd
->setex($this->key($key), $ttl +
60*60*24, $item);
66 $this->rd
->delete($this->key($key));
70 namespace app\Github\Storage\Redis
;
78 function __construct(array $data) {
79 foreach ($data as $key => $val) {