123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
-
-
-
- namespace Doctrine\Common\Cache;
-
- use Redis;
-
-
- class RedisCache extends CacheProvider
- {
-
-
- private $redis;
-
-
-
- public function setRedis(Redis $redis)
- {
- $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);
- $this->redis = $redis;
- }
-
-
-
- public function getRedis()
- {
- return $this->redis;
- }
-
-
-
- protected function doFetch($id)
- {
- return $this->redis->get($id);
- }
-
-
-
- protected function doContains($id)
- {
- return $this->redis->exists($id);
- }
-
-
-
- protected function doSave($id, $data, $lifeTime = 0)
- {
- $result = $this->redis->set($id, $data);
- if ($lifeTime > 0) {
- $this->redis->expire($id, $lifeTime);
- }
- return $result;
- }
-
-
-
- protected function doDelete($id)
- {
- return $this->redis->delete($id);
- }
-
-
-
- protected function doFlush()
- {
- return $this->redis->flushDB();
- }
-
-
-
- protected function doGetStats()
- {
- $info = $this->redis->info();
- return array(
- Cache::STATS_HITS => false,
- Cache::STATS_MISSES => false,
- Cache::STATS_UPTIME => $info['uptime_in_seconds'],
- Cache::STATS_MEMORY_USAGE => $info['used_memory'],
- Cache::STATS_MEMORY_AVAILIABLE => false
- );
- }
- }
|