首页 >php教程 >PHP源码 >BAE使用Redis作为内存缓存

BAE使用Redis作为内存缓存

PHP中文网
PHP中文网原创
2016-05-26 08:20:071563浏览

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(&#39;Redis&#39;))
			return false;
		
		try
		{
			$this->redis = new Redis();
			$this->redis->connect($host, $port, &#39;0.2&#39;);//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);
	}

}

                   

                   

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn