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 学習者の迅速な成長を支援します!