redis.php (772B)
1 <?php 2 namespace Cache; 3 class Redis { 4 private $expire; 5 private $cache; 6 7 public function __construct($expire) { 8 $this->expire = $expire; 9 10 $this->cache = new \Redis(); 11 $this->cache->pconnect(CACHE_HOSTNAME, CACHE_PORT); 12 } 13 14 public function get($key) { 15 $data = $this->cache->get(CACHE_PREFIX . $key); 16 return json_decode($data, true); 17 } 18 19 public function set($key,$value) { 20 $status = $this->cache->set(CACHE_PREFIX . $key, json_encode($value)); 21 if($status){ 22 $this->cache->setTimeout(CACHE_PREFIX . $key, $this->expire); 23 } 24 return $status; 25 } 26 27 public function delete($key) { 28 $this->cache->delete(CACHE_PREFIX . $key); 29 } 30 }