using System; using System.Configuration; namespace EasyModbusClient.redis { class ServiceStackRedisHelper { static string ConncetionRedisString = ConfigurationManager.AppSettings["ConncetionRedisString"]; // public static ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient(ConncetionRedisString); /// /// 把值存放到redis里边取 /// /// /// public static void SetValue(string pkey, string pvalue) { using (ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient(ConncetionRedisString)) { try { client.Db = 2; client.Set(pkey, pvalue); // YG.Log.Instance.WriteLogAdd($"redis->>{pkey}-->{pvalue}"); } catch (Exception ex) { YG.Log.Instance.WriteLogAdd($"25-->{pkey}-->{pvalue}-->{ex.Message}"); } } } public static void SetValue(string pkey, string pvalue,string redisstring) { using (ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient(redisstring)) { try { client.Set(pkey, pvalue); // YG.Log.Instance.WriteLogAdd($"redis->>{pkey}-->{pvalue}"); } catch (Exception ex) { YG.Log.Instance.WriteLogAdd($"25-->{pkey}-->{pvalue}-->{ex.Message}"); } } } /// /// 根据key获取redis里边的内容 /// /// /// public static string GetValue(string key) { string value = ""; using (ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient(ConncetionRedisString)) { if (!string.IsNullOrWhiteSpace(key)) { try { value = client.GetValue(key); } catch (Exception ex) { YG.Log.Instance.WriteLogAdd($"37-->{key}-->{ex.Message}-->{value}"); } } } return value; } /// /// /// /// /// 123456@192.168.170.203:6379 /// public static string GetValue(string key, string redisString) { string value = ""; using (ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient(redisString)) { if (!string.IsNullOrWhiteSpace(key)) { try { value = client.GetValue(key); } catch (Exception ex) { YG.Log.Instance.WriteLogAdd($"37-->{key}-->{ex.Message}-->{redisString}"); } } } return value; } } }