From: Michael Wallner Date: Wed, 20 May 2015 14:33:14 +0000 (+0200) Subject: use starge driver prefix option X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=5c1a4c8a5d83ea925f17c94e5ab996b92e31e240;p=pharext%2Fpharext.org use starge driver prefix option --- diff --git a/app/Github/Storage/Memcache.php b/app/Github/Storage/Memcache.php index 452574b..5e4959b 100644 --- a/app/Github/Storage/Memcache.php +++ b/app/Github/Storage/Memcache.php @@ -14,16 +14,13 @@ class Memcache implements Storage if (!$mc) { $mc = new \Memcached("pharext"); $mc->addServer("localhost", 11211); + $mc->setOption(\Memcached::OPT_PREFIX_KEY, "$ns:"); } $this->mc = $mc; } - private function key($key) { - return sprintf("%s:%s", $this->ns, $key); - } - function get($key, Item &$item = null, $update = false) { - if (!$item = $this->mc->get($this->key($key))) { + if (!$item = $this->mc->get($key)) { return false; } @@ -33,7 +30,7 @@ class Memcache implements Storage if ($item->getLTL() >= 0) { if ($update) { $item->setTimestamp(); - $this->mc->set($this->key($key), $item, $item->getTTL() + 60*60*24); + $this->mc->set($key, $item, $item->getTTL() + 60*60*24); } return true; } @@ -41,11 +38,11 @@ class Memcache implements Storage } function set($key, Item $item) { - $this->mc->set($this->key($key), $item, (null !== $item->getTTL()) ? $item->getTTL() + 60*60*24 : 0); + $this->mc->set($key, $item, (null !== $item->getTTL()) ? $item->getTTL() + 60*60*24 : 0); return $this; } function del($key) { - $this->mc->delete($this->key($key)); + $this->mc->delete($key); } } diff --git a/app/Github/Storage/Redis.php b/app/Github/Storage/Redis.php index c971687..c6db525 100644 --- a/app/Github/Storage/Redis.php +++ b/app/Github/Storage/Redis.php @@ -15,16 +15,13 @@ class Redis implements Storage $rd = new \Redis(); $rd->open("localhost"); $rd->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP); + $rd->setOption(\Redis::OPT_PREFIX, "$ns:"); } $this->rd = $rd; } - private function key($key) { - return sprintf("%s:%s", $this->ns, $key); - } - function get($key, Item &$item = null, $update = false) { - if (!$item = $this->rd->get($this->key($key))) { + if (!$item = $this->rd->get($key)) { return false; } @@ -34,7 +31,7 @@ class Redis implements Storage if ($item->getLTL() >= 0) { if ($update) { $item->setTimestamp(); - $this->rd->setex($this->key($key), $item->getTTL() + 60*60*24, $item); + $this->rd->setex($key, $item->getTTL() + 60*60*24, $item); } return true; } @@ -43,14 +40,14 @@ class Redis implements Storage function set($key, Item $item) { if (null === $item->getTTL()) { - $this->rd->set($this->key($key), $item); + $this->rd->set($key, $item); } else { - $this->rd->setex($this->key($key), $item->getTTL() + 60*60*24, $item); + $this->rd->setex($key, $item->getTTL() + 60*60*24, $item); } return $this; } function del($key) { - $this->rd->delete($this->key($key)); + $this->rd->delete($key); } } diff --git a/app/bootstrap/github.php b/app/bootstrap/github.php index e0defa7..e03cba0 100644 --- a/app/bootstrap/github.php +++ b/app/bootstrap/github.php @@ -16,19 +16,18 @@ $injector->share(Github\API::class) $config->$basic->auth->toArray(), 0); } + $logger = new Github\Logger($config); + // FIXME: configure through app.ini try { $cache = new Github\Storage\Redis("gh-cache"); } catch (\Exception $ex) { - try { - $cache = new Github\Storage\Memcache("gh-cache"); - } catch (\Exception $ex) { - $cache = null; - } + /* Memcached won't throw an exception */ + $cache = new Github\Storage\Memcache("gh-cache"); } return new Github\API( $config->github - ,new Github\Logger($config) + ,$logger ,new Github\Storage\Session("gh-tokens") ,$cache );