/// <summary> /// 获取Hash所有数据 For Dictionary /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Key"></param> /// <returns></returns> public static Dictionary <string, T> HashGetAll <T>(string Key = "") { var TypeArg = typeof(T).GenericTypeArguments; string _key = TypeArg.Count() <= 0 ? typeof(T).Name : TypeArg[0].Name; Key = string.IsNullOrWhiteSpace(Key) ? TypeArg.Count() <= 0 ? _key + "_Day" : _key + "_List_Day" : Key; return(RedisReadHelper.HashGetAll <T>(Key)); }
//获取指定的类型的所有数据 public static List <T> RetrieveSet <T>(string key) where T : class, new() { var value = new List <T>(); if (RedisReadHelper.KeyExists(key)) { var result = RedisReadHelper.SetMembers <T>(key);//内存取数 return(result); } return(value); }
/// <summary> /// 添加Sets数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <param name="Key"></param> /// <returns></returns> public static bool AddForSets <T>(T entity, string Key = "") where T : class, new() { var TypeArg = typeof(T).GenericTypeArguments; string _key = TypeArg.Count() <= 0 ? typeof(T).Name : TypeArg[0].Name; Key = string.IsNullOrWhiteSpace(Key) ? TypeArg.Count() <= 0 ? _key + "_Day" : _key + "_List_Day" : Key; if (RedisReadHelper.SetAdd <T>(Key, entity)) { return(true); } return(false); }
/// <summary> /// 添加Hash数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="data"></param> /// <param name="dataKey"></param> /// <param name="Key"></param> /// <returns></returns> public static bool AddForHash <T>(T data, string dataKey, string Key = "") where T : class, new() { var TypeArg = typeof(T).GenericTypeArguments; string _key = TypeArg.Count() <= 0 ? typeof(T).Name : TypeArg[0].Name; Key = string.IsNullOrWhiteSpace(Key) ? TypeArg.Count() <= 0 ? _key + "_Day" : _key + "_List_Day" : Key; if (RedisReadHelper.IsExist(Key, dataKey)) { RedisReadHelper.Remove(Key, dataKey); } return(RedisReadHelper.SetHash <T>(Key, dataKey, data)); }
/// <summary> /// 获取Sets所有数据 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static List <T> SetsGetAll <T>(string Key = "") where T : class, new() { var TypeArg = typeof(T).GenericTypeArguments; string _key = TypeArg.Count() <= 0 ? typeof(T).Name : TypeArg[0].Name; Key = string.IsNullOrWhiteSpace(Key) ? TypeArg.Count() <= 0 ? _key + "_Day" : _key + "_List_Day" : Key; var item = RedisReadHelper.SetMembers <T>(Key); if (item.Count <= 0) { return(item); } return(new List <T>()); }
/// <summary> /// 获取hash数据键值数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="QueryDB"></param> /// <param name="Datakey"></param> /// <param name="Key"></param> /// <returns></returns> public static T HashGet <T>(T QueryDB, string Datakey, string Key = "") where T : class, new() { var TypeArg = typeof(T).GenericTypeArguments; string _key = TypeArg.Count() <= 0 ? typeof(T).Name : TypeArg[0].Name; Key = string.IsNullOrWhiteSpace(Key) ? TypeArg.Count() <= 0 ? _key + "_Day" : _key + "_List_Day" : Key; var item = RedisReadHelper.HashGet <T>(Key, Datakey); if (item == null) { if (QueryDB != null) { item = QueryDB; AddForHash <T>(item, Datakey, Key); } } return(item); }
//Model注释 //获取指定的HashTable //public static List<T> RetrieveHash<T>(string key) where T : Ninth.Model.BaseModel, new() //{ // var value = new List<T>(); // if (RedisWriteHelper.KeyExists(key)) // { // var result = RedisWriteHelper.GetAll<T>(key);//内存取数 // return result; // } // //else // //{ // // value = _dbService.DataRepository.GetQueryable<T>().ToList();//数据取数据 // // if (value.Count() > 0) // // { // // foreach (var item in value) // // { // // RedisWriteHelper.SetHash<T>(key, item.GUID, item); // // } // // } // //} // return value; //} public static string GetHashKeyValue(string hashId, string key) { return(RedisReadHelper.Get(hashId, key)); }