Exemplo n.º 1
0
        //获取指定的类型的所有数据
        public static List <T> RetrieveSet <T>(string key) where T : class, new()
        {
            var value = new List <T>();

            if (RedisWriteHelper.KeyExists(key))
            {
                var result = RedisWriteHelper.SetMembersAsync <T>(key);//内存取数
                return(result.Result);
            }
            return(value);
        }
Exemplo n.º 2
0
        //根据IQueryable,获取指定的类型的部分数据
        //public static List<T> RetrieveSetByIQueryable<T>(string key, IQueryable<T> query) where T : class, new()
        public static List <T> RetrieveSetByIQueryable <T>(string key, IQueryable <T> query) where T : Model.BaseModel, new()
        {
            var value = new List <T>();

            if (RedisWriteHelper.KeyExists(key))
            {
                var result = RedisWriteHelper.SetMembersAsync <T>(key);//内存取数
                return(result.Result);
            }
            else
            {
                value = query.ToList();//数据取数据
                if (value.Count() > 0)
                {
                    foreach (var item in value)
                    {
                        RedisWriteHelper.SetAddAsync(key, JsonSerializer.SerializeToString(item)).Wait();
                        //RedisHelper.SetHash<T>(key, item.GUID, item);
                        //RedisHelper.SetAsync(item.GUID, item).Wait();
                    }
                }
            }
            return(value);
        }