Esempio n. 1
0
        //根据IQueryable,获取一条数据
        public static T GetModelByIQueryable <T>(string key, IQueryable <T> query, string HospitalID, string tableName) where T : class, new()
        {
            T value = null;

            if (RedisWriteHelper.KeyExists(key))
            {
                var result = RedisWriteHelper.StringGetAsync <T>(key);//内存取数
                return(result.Result);
            }
            else
            {
                try
                {
                    value = query.FirstOrDefault();               //数据取数据
                    RedisWriteHelper.SetAsync(key, value).Wait(); //加到内存里
                }
                catch (Exception)
                {
                    return(value);
                }
            }
            return(value);
        }