<span style= "FONT-SIZE:12PX;" ><?php/** * Redis Cache operation * @author HXM * @version 1.0 * @since 2015.05.04/class Rcache extends Object implemen TS Cacheface {private $redis = null;//redis Object Private $sId = 1; Servier Service ID Private $con = null;//Link Resource/** * initialization Redis * * @return Object/Public function __construct () {if (!class_exists (' Redis ')) {throw new qexception (' PHP extension does not Exist:redis
');
} $this->redis = new Redis (); /** * Link MEMCAHCE service * @access private * @param string $key keyword * @param string $value Cached content *
@return Array */Private Function Connect ($sid) {$file = $this->cachefile ();
Require $file;
if (! isset ($cache)) {throw new Qexception (' cache configuration file does not exist '. $file);
} $server = $cache [$this->cacheid]; $sid = Isset ($sid) = = 0? $this->sid: $sid;//memcache Service Select if (! $server [$sid]) {throw new QException (' The cached server configuration file for the current operation does not exist ');
$host = $server [$sid] [' Host '];
$port = $server [$sid] [' Port '];
try {$this->redis->connect ($host, $port);
The catch (Exception $e) {exit (' Memecache connection failed, error message: '. $e->getmessage ()); }/** * Write cache * @access Private * @param string $key keyword * @param string $value cache content * @re Turn array */Public function set ($key, $value, $sid, $expire = 0) {$data = $this->get ($key, $sid);
If there is already a key value if ($data) {return $this->redis->getset ($key, $value);
else {return $this->redis->set ($key, $value);
}/** * Read cache * @access private * @param string $key keyword * @param int $sid Select the first few memcache servers
* @return Array */Public function get ($key, $sid) {$this->connect ($SID);
return $this->redis->get ($key); /** * Clean (delete) All elements that have been stored * * @access Private * @returN Array */Public function flush () {$this->connect ();
return $this->redis->flushall (); /** * Delete Cache * * @access private * @param string $key keyword * @param int $sid Select the first few memcache servers * @re
Turn array */Public function remove ($key, $sid) {$this->connect ();
return $this->redis->del ($key); /** * destructor * finally closes memcache/public Function __destruct () {if ($this->redis) {$thi
S->redis->close (); }}}</span>