//连接缓存
$redis = new Redis();
$redisServer = Configure::read('redis.server');
$redis->connect($redisServer['host'], $redisServer['port']);
if (!empty($redisServer['pwd'])) {
$redis->auth($redisServer['pwd']); //登录验证密码 返回true/false
}
$redis = new Redis();
$redisServer = Configure::read('redis.server');
$redis->connect($redisServer['host'], $redisServer['port']);
if (!empty($redisServer['pwd'])) {
$redis->auth($redisServer['pwd']); //登录验证密码 返回true/false
}
$result = $redis->get($id);
if(empty($result)) //获取失败为空,不是网上说是$result==false
{
$redis->set($id, '1');
$redis->expire($id,120);//120秒自动删除缓存记录$key=$id
}
$redis->close();