redis = new Predis\Client(array( 'scheme'=>'tcp', 'host'=>$host, 'port'=>$port, 'password'=>$pwd, )); $this->redis->select($db); return $this; } public function get($key){ $result = $this->redis->get($key); if (!$result || $result == "" || $result == null){ return null; } return JsonUtil::decode($result); } public function getMulti($keys) { $ctx = $this->redis->mget($keys); $count = count($ctx); for($i = 0; $i < $count; $i++) { $ctx[$i] = JsonUtil::decode($ctx[$i]); } return $ctx; } public function set($key, $val) { if($val == null || $val == ""){ return false; } $ret = $this->redis->set($key, JsonUtil::encode($val)); return "OK" == $ret; } public function cas($key, $value){ return $this->set($key, $value); } public function delete($key) { $infos = array(); $infos[] = $key; return $this->redis->del($infos) == 1; } public function increment($key) { return $this->redis->incr($key); } public function copy($surKey, $desKey) { return $this->set($desKey, $this->get($surKey)); } public function close() { $this->redis->quit(); } /** * 获得Redis扩展客户端 * @return Predis\Client */ public function getRedisClient(){ return $this->redis; } /** * 错误中断 * @param type $msg */ function halt($msg=null){ exit($msg.'
'.$this->redis->getLastError()); } }