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