瀏覽代碼

😁修复前端页面显示redis缓存值异常

zuohuaijun 2 年之前
父節點
當前提交
5f3ab823dd
共有 2 個文件被更改,包括 19 次插入15 次删除
  1. 2 2
      Admin.NET/Admin.NET.Core/Service/Cache/SysCacheService.cs
  2. 17 13
      Web/src/views/system/cache/index.vue

+ 2 - 2
Admin.NET/Admin.NET.Core/Service/Cache/SysCacheService.cs

@@ -32,7 +32,7 @@ public class SysCacheService : IDynamicApiController, ISingleton
     public List<string> GetKeyList()
     {
         // 键名去掉全局缓存前缀
-        return _cache.Keys.Select(u => u[_cacheOptions.Prefix.Length..]).OrderBy(u => u).ToList();
+        return _cache.Keys.Where(u => u.StartsWith(_cacheOptions.Prefix)).Select(u => u[_cacheOptions.Prefix.Length..]).OrderBy(u => u).ToList();
     }
 
     /// <summary>
@@ -128,7 +128,7 @@ public class SysCacheService : IDynamicApiController, ISingleton
     [DisplayName("获取缓存值")]
     public object GetValue(string key)
     {
-        return _cache.Get<object>($"{_cacheOptions.Prefix}{key}");
+        return _cache == Cache.Default ? _cache.Get<object>($"{_cacheOptions.Prefix}{key}") : _cache.Get<string>($"{_cacheOptions.Prefix}{key}");
     }
 
     /// <summary>

+ 17 - 13
Web/src/views/system/cache/index.vue

@@ -124,21 +124,25 @@ const nodeClick = async (node: any) => {
 	currentNode.value = node;
 	state.loading1 = true;
 	var res = await getAPI(SysCacheApi).apiSysCacheValueKeyGet(node.id);
-	state.cacheValue = res.data.result;
+	// state.cacheValue = JSON.parse(res.data.result);
+	var result = res.data.result;
+	if (typeof result == 'string') {
+		try {
+			var obj = JSON.parse(result);
+			if (typeof obj == 'object') {
+				state.cacheValue = obj;
+			} else {
+				state.cacheValue = result;
+			}
+		} catch (e) {
+			state.cacheValue = result;
+		}
+	} else {
+		state.cacheValue = result;
+	}
+
 	state.cacheKey = node.id;
 	state.loading1 = false;
-
-	// var result = res.data.result;
-	// try {
-	// 	var obj = JSON.parse(result);
-	// 	if (typeof obj === 'object' && obj) {
-	// 		state.cacheValue = obj;
-	// 	} else {
-	// 		state.cacheValue = result;
-	// 	}
-	// } catch (e) {
-	// 	state.cacheValue = result;
-	// }
 };
 </script>