bae内存缓存(phpredis) <?php
/*
* redis cache
*/
class cache
{
private $redis = null;//only this class
private $mysql = null;
public function __construct($host, $port, $username, $password, $database)
{
if (!class_exists('redis'))
return false;
try
{
$this->redis = new redis();
$this->redis->connect($host, $port, '0.2');//timeout 200ms
$this->redis->auth("{$username}-{$password}-{$database}");
}
catch (redisexception $error)
{
return false;
//var_dump($error);
}
}
public function get($key)
{
return $this->redis->get($key);
}
public function set($key, $value, $express=0)
{
if ($express)
return $this->redis->setex($key, $express, $value);
else
return $this->redis->set($key, $value);
}
public function delete($key)
{
return $this->redis->delete($key);
}
}