using System; using System.Collections.Generic; using System.Linq; using MySystem.Models; namespace MySystem { public class AdvertismentDbconn { public readonly static AdvertismentDbconn Instance = new AdvertismentDbconn(); #region 获取列表 public List GetList(string ColId) { string key = "AdvertismentList:" + ColId; List list = new List(); if (RedisDbconn.Instance.Exists(key)) { list = RedisDbconn.Instance.GetList(key); if (list.Count > 0) { return list; } } List newlist = new List(); WebCMSEntities db = new WebCMSEntities(); var mysqllist = db.Advertisment.Where(m => m.ColId == ColId).OrderByDescending(m => m.Sort).OrderByDescending(m => m.Id).ToList(); if (mysqllist.Count > 0) { foreach (var sub in mysqllist) { newlist.Add(sub); } RedisDbconn.Instance.Clear(key); foreach (Advertisment sub in newlist) { RedisDbconn.Instance.AddRightList(key, sub); } } db.Dispose(); return newlist; } #endregion } }