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

BAE使用Redis作为内存缓存

PHP中文网
PHP中文网Original
2016-05-26 08:20:071556browse

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);
	}

}

                   

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn