Beispiel #1
0
        public async Task <List <PostInfo> > GetRecentPostAsync(int count)
        {
            using (MVCBlogContext Context = new MVCBlogContext())
            {
                Func <List <int> > GetIds = () =>
                {
                    return(Context.PostInfo.OrderByDescending(x => x.Id).Take(count).Select(x => x.Id).ToList());
                };
                //var res = Context.PostInfo.OrderByDescending(x => x.Id).Take(count).Select(x => x.Id).ToList();
                var res = await GetIds.StartAsync <List <int> >();

                if (res != null && res.Count > 0)
                {
                    List <PostInfo> list = new List <PostInfo>();
                    foreach (var item in res)
                    {
                        string          key   = RedisKeyHelper.GetPostKey(item);
                        Func <PostInfo> GetDb = () => GetFromDB(item);
                        PostInfo        info  = RedisHelper.GetEntity <PostInfo>(key, GetDb);
                        list.Add(info);
                    }
                    return(list);
                }
                return(new List <PostInfo>());
            }
        }
Beispiel #2
0
 public override string GetModelKey(int id)
 {
     return(RedisKeyHelper.GetPostKey(id));
 }