redis = new Redis(); $ret = $this->redis->connect($host, $port); if($ret==null || !$ret){ $this->halt("connect failed!"); } $this->redis->select($db); return $ret; } public function get($key){ $result = $this->redis->get($key); if (!$result || $result == "" || $result == null){ return null; } return JsonUtil::decode($result); } public function set($key, $val) { if($val == null || $val == ""){ return false; } $ret = $this->redis->set($key, JsonUtil::encode($val)); return "OK" == $ret; } public function delete($key) { $infos = array(); $infos[] = $key; return $this->redis->del($infos); } public function cas($key, $value) { return $this->set($key, $value); } public function copy($surKey, $desKey) { return $this->set($desKey, $this->get($surKey)); } public function close() { $this->redis->close(); } /** * 获得Redis扩展客户端 * @return Redis */ public function getRedisClient(){ return $this->redis; } /** * 错误中断 * @param type $msg */ function halt($msg=null){ exit($msg.'
'.$this->redis->getLastError()); } }