首頁 > php教程 > PHP源码 > 主體

BAE使用Redis作为内存缓存

PHP中文网
發布: 2016-05-26 08:20:07
原創
1486 人瀏覽過

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

}
登入後複製

                   

                   

相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!