|
@@ -1,426 +0,0 @@
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using Library;
|
|
|
-
|
|
|
-namespace MySystem
|
|
|
-{
|
|
|
- public class BothdisDbconn
|
|
|
- {
|
|
|
- public readonly static BothdisDbconn Instance = new BothdisDbconn();
|
|
|
-
|
|
|
-
|
|
|
- public void SendMq(string key, object obj)
|
|
|
- {
|
|
|
- SetRedisDataList data = new SetRedisDataList()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- val = Newtonsoft.Json.JsonConvert.SerializeObject(obj),
|
|
|
- };
|
|
|
- RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(data), "SetRedisDataList");
|
|
|
- }
|
|
|
-
|
|
|
- #region 设置单个字段
|
|
|
- public void Set(string key, object value)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.Set(key, value))
|
|
|
- {
|
|
|
- RedisDbconn.Instance.Clear(key);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:Set");
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 整数累加
|
|
|
- public void AddInt(string key, long value = 1)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.AddInt(key, value) > 0)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.Clear(key);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:AddInt");
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 数字累加
|
|
|
- public void AddNumber(string key, decimal value = 1)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.AddNumber(key, value) > 0)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.Clear(key);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:AddNumber");
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 获取单个字段
|
|
|
- public T Get<T>(string key)
|
|
|
- {
|
|
|
- T obj = RedisDbconn.Instance.Get<T>(key);
|
|
|
- if (obj != null)
|
|
|
- {
|
|
|
- return obj;
|
|
|
- }
|
|
|
- T newobj = RedisDbconn.Instance.Get<T>(key);
|
|
|
- if (newobj != null)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.Set(key, newobj);
|
|
|
- }
|
|
|
- return newobj;
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 设置散列字段
|
|
|
- public void HSet(string key, string field, object value)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.HSet(key, field, value))
|
|
|
- {
|
|
|
- RedisDbconn.Instance.HSet(key, field, value);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:HSet");
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 散列整数累加
|
|
|
- public void HAddInt(string key, string field, long value = 1)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.HAddInt(key, field, value) > 0)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.HAddInt(key, field, value);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:HAddInt");
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 散列数字累加
|
|
|
- public void HAddNumber(string key, string field, decimal value = 1)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.HAddNumber(key, field, value) > 0)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.HAddNumber(key, field, value);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:HAddNumber");
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 获取散列元素
|
|
|
- public T HGet<T>(string key, string field)
|
|
|
- {
|
|
|
- T obj = RedisDbconn.Instance.HGet<T>(key, field);
|
|
|
- if (obj != null)
|
|
|
- {
|
|
|
- return obj;
|
|
|
- }
|
|
|
- T newobj = RedisDbconn.Instance.HGet<T>(key, field);
|
|
|
- if (newobj != null)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.HSet(key, field, newobj);
|
|
|
- }
|
|
|
- return newobj;
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 获取散列所有元素
|
|
|
- public Dictionary<string, T> HGetAll<T>(string key)
|
|
|
- {
|
|
|
- Dictionary<string, T> obj = RedisDbconn.Instance.HGetAll<T>(key);
|
|
|
- if (obj != null)
|
|
|
- {
|
|
|
- return obj;
|
|
|
- }
|
|
|
- Dictionary<string, T> newobj = RedisDbconn.Instance.HGetAll<T>(key);
|
|
|
- if (newobj != null)
|
|
|
- {
|
|
|
- foreach (string sub in newobj.Keys)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.HSet(key, sub, newobj[sub]);
|
|
|
- }
|
|
|
- }
|
|
|
- return newobj;
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 添加集合对象
|
|
|
- public void SAdd(string key, object value)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.SAdd(key, value) > 0)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.SAdd(key, value);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:SAdd");
|
|
|
- }
|
|
|
- }
|
|
|
- public void SAdd(string key, object[] value)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.SAdd(key, value) > 0)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.SAdd(key, value);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:SAdd");
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 获取集合对象
|
|
|
- public T[] SGetList<T>(string key)
|
|
|
- {
|
|
|
- T[] obj = RedisDbconn.Instance.SGetList<T>(key);
|
|
|
- if (obj != null)
|
|
|
- {
|
|
|
- if (obj.Length > 0)
|
|
|
- {
|
|
|
- return obj;
|
|
|
- }
|
|
|
- }
|
|
|
- T[] newobj = RedisDbconn.Instance.SGetList<T>(key);
|
|
|
- if (newobj != null)
|
|
|
- {
|
|
|
- foreach (T sub in newobj)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.SAdd(key, sub);
|
|
|
- }
|
|
|
- }
|
|
|
- return newobj;
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 添加列表对象
|
|
|
- public void AddList(string key, object value)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.AddList(key, value) > 0)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.Clear(key);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:AddList");
|
|
|
- }
|
|
|
- }
|
|
|
- public void AddList(string key, object[] value)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.AddList(key, value) > 0)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.Clear(key);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:AddList");
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 获取列表
|
|
|
- public List<T> GetList<T>(string key, int pageNum = 1, int pageSize = 10)
|
|
|
- {
|
|
|
- List<T> list = RedisDbconn.Instance.GetList<T>(key, pageNum, pageSize);
|
|
|
- if (list.Count > 0)
|
|
|
- {
|
|
|
- return list;
|
|
|
- }
|
|
|
- return RedisDbconn.Instance.GetList<T>(key, pageNum, pageSize);
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 添加排序列表对象
|
|
|
- public void AddSort(string key, object value, decimal score)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.AddSort(key, value, score) > 0)
|
|
|
- {
|
|
|
- RedisDbconn.Instance.AddSort(key, value, score);
|
|
|
- int Expired = 60 * 60 * 24 * 180;
|
|
|
- RedisDbconn.Instance.SetExpire(key, Expired);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- value = value,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:AddSort");
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 获取排序列表
|
|
|
- public List<T> GetSort<T>(string key, int pageNum = 1, int pageSize = 10)
|
|
|
- {
|
|
|
- List<T> list = RedisDbconn.Instance.GetSort<T>(key, pageNum, pageSize);
|
|
|
- if (list.Count > 0)
|
|
|
- {
|
|
|
- return list;
|
|
|
- }
|
|
|
- return RedisDbconn.Instance.GetSort<T>(key, pageNum, pageSize);
|
|
|
- }
|
|
|
- public List<T> GetSortDesc<T>(string key, int pageNum = 1, int pageSize = 10)
|
|
|
- {
|
|
|
- List<T> list = RedisDbconn.Instance.GetSortDesc<T>(key, pageNum, pageSize);
|
|
|
- if (list.Count > 0)
|
|
|
- {
|
|
|
- return list;
|
|
|
- }
|
|
|
- return RedisDbconn.Instance.GetSortDesc<T>(key, pageNum, pageSize);
|
|
|
- }
|
|
|
- #endregion
|
|
|
-
|
|
|
- public void Remove(string key, long start, long end)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (RedisDbconn.Instance.Remove(key, start, end))
|
|
|
- {
|
|
|
- RedisDbconn.Instance.Remove(key, start, end);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = key,
|
|
|
- start = start,
|
|
|
- end = end,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:Remove");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void RemoveTop(string key, long count)
|
|
|
- {
|
|
|
- Remove(key, count, RedisDbconn.Instance.Count(key) - 1);
|
|
|
- }
|
|
|
-
|
|
|
- public void Clear(string pattern)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- TendisDbconn.Instance.Clear(pattern);
|
|
|
- RedisDbconn.Instance.Clear(pattern);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- TendisErr err = new TendisErr()
|
|
|
- {
|
|
|
- key = pattern,
|
|
|
- errMsg = ex.ToString(),
|
|
|
- };
|
|
|
- function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(err), "Tendis:Clear");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|