using System; using System.Collections.Generic; using System.Linq; using MySystem.MainModels; namespace MySystem { public class KqProductsDbconn { public readonly static KqProductsDbconn Instance = new KqProductsDbconn(); #region 获取列表 public List GetList() { string key = "KqProducts"; List list = new List(); if (RedisDbconn.Instance.Exists(key)) { list = RedisDbconn.Instance.GetList(key, 1, 100); if (list.Count > 0) { return list; } } List newlist = new List(); RedisDbconn.Instance.GetLock(key + ":lock"); WebCMSEntities db = new WebCMSEntities(); var mysqllist = db.KqProducts.Where(m => m.Status == 1).OrderBy(m => m.Id).ToList(); if (mysqllist.Count > 0) { foreach (var sub in mysqllist) { newlist.Add(sub); } RedisDbconn.Instance.Clear(key); foreach (KqProducts sub in newlist) { RedisDbconn.Instance.AddRightList(key, sub); } } db.Dispose(); RedisDbconn.Instance.ReleaseLock(key + ":lock"); return newlist; } #endregion } }