Kaynağa Gözat

redis user-dict key 加前缀

visuddhinanda 3 yıl önce
ebeveyn
işleme
4ed9b570ab

+ 26 - 27
app/Http/Controllers/UserDictController.php

@@ -295,34 +295,33 @@ class UserDictController extends Controller
 
 	private function update_redis($word){
 		#更新 redis
-
-		//if ($this->redis != false) 
-		{
-			{
-				$Fetch = UserDict::where(['word'=>$word['word'],"source"=>"_SYS_USER_WBW_"])->get();
-				$redisWord=array();
-				foreach ($Fetch as  $one) {
-					# code...
-					$redisWord[] = array(
-									$one["id"],
-									$one["word"],
-									$one["type"],
-									$one["grammar"],
-									$one["parent"],
-									$one["mean"],
-									$one["note"],
-									$one["factors"],
-									$one["factormean"],
-									$one["status"],
-									$one["confidence"],
-									$one["creator_id"],
-									$one["source"],
-									$one["language"]
-									);
-				}
-				Redis::hSet("dict://user",$word['word'],json_encode($redisWord,JSON_UNESCAPED_UNICODE));			
-			}
+		$Fetch = UserDict::where(['word'=>$word['word'],"source"=>"_USER_WBW_"])->get();
+		$redisWord=array();
+		foreach ($Fetch as  $one) {
+			# code...
+			$redisWord[] = array(
+							$one["id"],
+							$one["word"],
+							$one["type"],
+							$one["grammar"],
+							$one["parent"],
+							$one["mean"],
+							$one["note"],
+							$one["factors"],
+							$one["factormean"],
+							$one["status"],
+							$one["confidence"],
+							$one["creator_id"],
+							$one["source"],
+							$one["language"]
+							);
 		}
+		$redisData = json_encode($redisWord,JSON_UNESCAPED_UNICODE);
+		Log::info("word={$word['word']} redis-data={$redisData}");
+		Redis::hSet("dict/user",$word['word'],$redisData);
+		$redisData1 = Redis::hGet("dict/user",$word['word']);
+		Log::info("word={$word['word']} redis-data1={$redisData1}");
+
 		#更新redis结束
 	}
 

+ 2 - 1
public/app/dict/dict_lookup.php

@@ -341,7 +341,8 @@ function lookup_user($word){
 	$Fetch=array();
 	
 	if($redis){
-		$wordData = $redis->hGet("dict://user",$word);
+		$rediskey = Redis["prefix"]."dict/user";
+		$wordData = $redis->hGet($rediskey,$word);
 			if($wordData){
 				if(!empty($wordData)){
 					$arrWord = json_decode($wordData,true);

+ 4 - 4
public/app/dict/redis_import_user.php

@@ -2,7 +2,7 @@
 require_once __DIR__."/../config.php";
 require_once __DIR__."/../redis/function.php";
 
-$rediskey = "dict://user";
+$rediskey = Redis["prefix"]."dict/user";
 if (PHP_SAPI == "cli") {
 	$redis = redis_connect();
 	if ($redis != false) {
@@ -12,7 +12,7 @@ if (PHP_SAPI == "cli") {
 		$stmtPli = $dbh->query($query);
 		while ($word = $stmtPli->fetch(PDO::FETCH_ASSOC)) {
 			# code...
-			$query = "SELECT * from "._TABLE_DICT_WBW_." where word = ? and source = '_USER_DATA_' ";
+			$query = "SELECT * from "._TABLE_DICT_WBW_." where word = ? and (source = '_USER_DATA_' or source = '_USER_WBW_') ";
 			$stmt = $dbh->prepare($query);
 			$stmt->execute(array($word["word"]));
 			if ($stmt) {
@@ -24,8 +24,8 @@ if (PHP_SAPI == "cli") {
 									$one["id"],
 									$one["word"],
 									$one["type"],
-									$one["gramma"],
-									$one["base"],
+									$one["grammar"],
+									$one["parent"],
 									$one["mean"],
 									$one["note"],
 									$one["factors"],

+ 1 - 1
public/app/studio/dict_find_auto.php

@@ -101,7 +101,7 @@ array_push($db_file_list, array(_DIR_DICT_3RD_ . "/uhan_en.db", ""));
 
 $db_file_list[] = array("","wbwdict://new/".$_COOKIE["userid"],true);	
 $db_file_list[] = array(_FILE_DB_TERM_,"dict://term",true);	
-$db_file_list[] = array(_FILE_DB_WBW1_,"dict://user",true);
+$db_file_list[] = array(_FILE_DB_WBW1_,Redis["prefix"]."dict/user",true);
 
 $db_file_list[] = array( _DIR_DICT_SYSTEM_ . "/sys_regular.db","dict://regular",true);
 $db_file_list[] = array( _DIR_DICT_SYSTEM_ . "/sys_irregular.db","dict://irregular",true);

+ 1 - 1
public/app/studio/dict_find_one.php

@@ -70,7 +70,7 @@ $db_file_list = array();
 //词典列表
 if ($dict_name == "") {
     $db_file_list[] = array(_FILE_DB_TERM_,"dict://term",true);	
-	$db_file_list[] = array(_FILE_DB_WBW1_,"dict://user",true);
+	$db_file_list[] = array(_FILE_DB_WBW1_,Redis["prefix"]."dict/user",true);
 	
     $db_file_list[] = array( _DIR_DICT_SYSTEM_ . "/sys_regular.db","dict://regular",true);
     $db_file_list[] = array( _DIR_DICT_SYSTEM_ . "/sys_irregular.db","dict://irregular",true);