123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 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);
- /// <summary>
- /// 把值存放到redis里边取
- /// </summary>
- /// <param name="key"></param>
- /// <param name="value"></param>
- public static void SetValue(string pkey, string pvalue)
- {
- using (ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient(ConncetionRedisString))
- {
- try
- {
- client.Db = 2;
- client.Set<string>(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<string>(pkey, pvalue);
- // YG.Log.Instance.WriteLogAdd($"redis->>{pkey}-->{pvalue}");
- }
- catch (Exception ex)
- {
- YG.Log.Instance.WriteLogAdd($"25-->{pkey}-->{pvalue}-->{ex.Message}");
- }
- }
- }
- /// <summary>
- /// 根据key获取redis里边的内容
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="key"></param>
- /// <param name="redisString">123456@192.168.170.203:6379</param>
- /// <returns></returns>
- 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;
- }
- }
- }
|