X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=app%2FGithub%2FStorage%2FRedis.php;h=c971687aa1b0e44f2e4ed811abe6d527635db935;hb=eb76e9bb9a39fe2725301f6cf6fc3cf29bbc4e00;hp=5833a5bae854c1267dcd2ce922c786ebdbb6daa7;hpb=7127fbd60ef118a688b5c4270ed73369b2b2424a;p=pharext%2Fpharext.org diff --git a/app/Github/Storage/Redis.php b/app/Github/Storage/Redis.php index 5833a5b..c971687 100644 --- a/app/Github/Storage/Redis.php +++ b/app/Github/Storage/Redis.php @@ -23,42 +23,29 @@ class Redis implements Storage return sprintf("%s:%s", $this->ns, $key); } - function get($key, &$val = null, &$ltl = null, $update = false) { + function get($key, Item &$item = null, $update = false) { if (!$item = $this->rd->get($this->key($key))) { - header("Cache-Item: ".serialize($item), false); return false; } - $val = $item->value; - $ttl = $item->ttl; - $set = $item->time; - - if (!isset($ttl)) { + if (null === $item->getTTL()) { return true; } - $now = time(); - $ltl = $ttl - ($now - $set); - header("X-Cache-Times: ltl=$ltl,now=$now,set=$set,ttl=$ttl", false); - if ($ltl >= 0) { + if ($item->getLTL() >= 0) { if ($update) { - $item->time = time(); - $this->rd->setex($this->key($key), $ttl + 60*60*24, $item); + $item->setTimestamp(); + $this->rd->setex($this->key($key), $item->getTTL() + 60*60*24, $item); } return true; } return false; } - function set($key, $val, $ttl = null) { - $item = new Redis\Item([ - "value" => $val, - "ttl" => $ttl, - "time" => isset($ttl) ? time() : null - ]); - if (isset($ttl)) { + function set($key, Item $item) { + if (null === $item->getTTL()) { $this->rd->set($this->key($key), $item); } else { - $this->rd->setex($this->key($key), $ttl + 60*60*24, $item); + $this->rd->setex($this->key($key), $item->getTTL() + 60*60*24, $item); } return $this; } @@ -67,19 +54,3 @@ class Redis implements Storage $this->rd->delete($this->key($key)); } } - -namespace app\Github\Storage\Redis; - -class Item -{ - public $value; - public $time; - public $ttl; - - function __construct(array $data) { - foreach ($data as $key => $val) { - $this->$key = $val; - } - } -} -