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);
41 header("X-Cache-Times: ltl=$ltl,now=$now,set=$set,ttl=$ttl", false);
45 $this->rd
->setex($this->key($key), $ttl +
60*60*24, $item);
52 function set($key, $val, $ttl = null) {
53 $item = new Redis\
Item([
56 "time" => isset($ttl) ?
time() : null
59 $this->rd
->set($this->key($key), $item);
61 $this->rd
->setex($this->key($key), $ttl +
60*60*24, $item);
67 $this->rd
->delete($this->key($key));
71 namespace app\Github\Storage\Redis
;
79 function __construct(array $data) {
80 foreach ($data as $key => $val) {