From 48d3dbdcb7818fa9634b23d8d063387b1755c60e Mon Sep 17 00:00:00 2001 From: XuJiacheng Date: Sat, 20 Dec 2025 15:22:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9ARedis=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E5=92=8CCRICS=E4=BA=A4=E6=8D=A2=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + UI/CSRedisCacheHelper.cs | 95 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 UI/CSRedisCacheHelper.cs diff --git a/.gitignore b/.gitignore index 64154a9..d4cc2ef 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ UI/App_Data/UDPLog/ /UI/*.user /UI/Properties/PublishProfiles/*.user /UI/Properties/PublishProfiles/*.user +/UI/Properties/PublishProfiles diff --git a/UI/CSRedisCacheHelper.cs b/UI/CSRedisCacheHelper.cs new file mode 100644 index 0000000..8081da4 --- /dev/null +++ b/UI/CSRedisCacheHelper.cs @@ -0,0 +1,95 @@ +using CSRedis; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using static CSRedis.CSRedisClient; + +namespace Common +{ + /// + /// Redis缓存辅助类 + /// + 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"; + 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"); + var DingYueMsg = ("CellCorelDRAWUser", new Action(async (args) => + { + string body = args.Body; + })); + + CSRedisCacheHelper.redis.Subscribe(DingYueMsg); + } + } + /// + /// 添加缓存 + /// + /// + /// + /// + public static void Set(string key, T value, int ExpireTime) + { + redis?.Set(key, value, ExpireTime * 60); + } + + public static T Get(string key) + { + return redis.Get(key); + } + + public static void Forever(string key, T value) + { + redis.Set(key, value, -1); + } + public static void Del(string key) + { + redis.Del(key); + } + + /// + /// 判断是否存在 + /// + /// + /// + + public static bool Contains(string key) + { + bool result = redis.Exists(key); + return result; + } + + /// + /// 发布消息 + /// + /// + /// + public static void Publish(string Topic, string Payload) + { + CSRedisCacheHelper.redis.PublishNoneMessageId(Topic, Payload); + } + + + public static void LPush(string Key, Dictionary Value) + { + CSRedisCacheHelper.redis.LPush>(Key,Value); + } + + public static T BRPop(string Key) + { + return CSRedisCacheHelper.redis.BRPop(3,Key); + } + } +}