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); + } + } +}