From 67f919218245597c019ec08e11f4b5529692b606 Mon Sep 17 00:00:00 2001 From: TianMaiCheng <746290578@qq.com> Date: Sat, 20 Dec 2025 15:35:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9ERedis=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UI/CSRedisCacheHelper.cs | 51 ++++++++++++++++++++++++++++------ UI/Controllers/WxController.cs | 11 +++++++- UI/UI.csproj | 6 ++++ UI/packages.config | 2 ++ 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/UI/CSRedisCacheHelper.cs b/UI/CSRedisCacheHelper.cs index 8081da4..9a33bd2 100644 --- a/UI/CSRedisCacheHelper.cs +++ b/UI/CSRedisCacheHelper.cs @@ -13,19 +13,15 @@ namespace Common /// public class CSRedisCacheHelper { - public static CSRedisClient? redis; - public static CSRedisClient? redis1; - - private const string ip = "10.8.8.208"; - //private const string port = "6379"; - private const string port = "10079"; + public static CSRedisClient redis; + private const string ip = "localhost"; + private const string port = "26379"; static CSRedisCacheHelper() { var redisHostStr = string.Format("{0}:{1}", ip, port); if (!string.IsNullOrEmpty(redisHostStr)) { - redis = new CSRedisClient(redisHostStr + ",password=blw@redis-ser@123,defaultDatabase=0"); - redis1 = new CSRedisClient(redisHostStr + ",password=blw@redis-ser@123,defaultDatabase=1"); + redis = new CSRedisClient(redisHostStr + ",password=1001^_^lool,defaultDatabase=0"); var DingYueMsg = ("CellCorelDRAWUser", new Action(async (args) => { string body = args.Body; @@ -91,5 +87,44 @@ namespace Common { return CSRedisCacheHelper.redis.BRPop(3,Key); } + + + /// + /// 添加Hash缓存 + /// + /// + /// + /// + public static void HMSet(string key, params object[] value) + { + redis.HMSet(key, value); + } + + public static void HMSet(int ExpireTime_M, string key, params object[] value) + { + redis.HMSet(key, value); + redis.Expire(key, new TimeSpan(0, ExpireTime_M, 0)); + } + /// + /// 获取Hash缓存 + /// + /// + /// + /// + public static T[] HMGet(string key, string KeyV) + { + return redis.HMGet(key, KeyV); + } + + /// + /// Example + /// WXFault_酒店编号_房间号 + /// + /// + /// + public static Dictionary HMGetAll(string key) + { + return redis.HGetAll(key); + } } } diff --git a/UI/Controllers/WxController.cs b/UI/Controllers/WxController.cs index 5a4014d..a5be5c8 100644 --- a/UI/Controllers/WxController.cs +++ b/UI/Controllers/WxController.cs @@ -1,4 +1,5 @@ -using Models; +using Common; +using Models; using Models.ModelItems; using Models.View; using Newtonsoft.Json; @@ -1589,6 +1590,14 @@ namespace UI.Controllers return ri; } + public void A() + { + string code = ""; + string roonumber = ""; + string a = $"WXFault_{code}_{roonumber}"; + CSRedisCacheHelper.HMGetAll("'"); + } + diff --git a/UI/UI.csproj b/UI/UI.csproj index c1307d3..7cbe501 100644 --- a/UI/UI.csproj +++ b/UI/UI.csproj @@ -50,6 +50,9 @@ ..\packages\BouncyCastle.1.8.5\lib\BouncyCastle.Crypto.dll + + ..\packages\CSRedisCore.3.8.807\lib\net45\CSRedisCore.dll + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll @@ -117,6 +120,9 @@ ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + diff --git a/UI/packages.config b/UI/packages.config index 00846aa..f59fbf9 100644 --- a/UI/packages.config +++ b/UI/packages.config @@ -3,6 +3,7 @@ + @@ -35,5 +36,6 @@ + \ No newline at end of file