(4)存儲單詞和翻譯

這個類的功能比較簡單,就是把單詞和翻譯存入到redis,並且查詢單詞也是在這個類裏完成的

<?php
require_once "format.class.php";
class StoreWord
{
	private $redis=null;
	private $trans;
	public function __construct()
	{
		$this->redis=new Redis();
		$this->redis->connect('127.0.0.1', 6379);
		$this->redis->auth('caifangjie');
	}
	
	public function setWord($wordZone,$word)
	{
		$hName=strtolower($wordZone).':OFX';
		foreach ($word as $key => $value)
		{
			$this->redis->hSetNx($hName, $key,$value);
		}
	}
	public function getWord($wordZone,$key)
	{
		$hName=$wordZone.':OFX';
		if($this->redis->hExists($hName, $key))
		{
			return $this->redis->hGet($hName, $key);
		}
		else
		{
			return 0;
		}
	}
	
	public function getAllWord($wordZone)
	{
		$hName=$wordZone.':OFX';
		return $this->redis->hKeys($hName);
	}
	public function getNumWord($wordZone)
	{
		$hName=$wordZone.':OFX';
		return $this->redis->hLen($hName);
	}
}

/* $redis=new StoreWord();
//$redis->setWord('a', array('all'=>'全部,所有', 'about'=>'關於','above'=>'上面,上部'));
var_dump( $redis->getWord('m-a', 'make')); */
?>


發佈了80 篇原創文章 · 獲贊 7 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章