KqProductsDbconn.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.MainModels;
  5. namespace MySystem
  6. {
  7. public class KqProductsDbconn
  8. {
  9. public readonly static KqProductsDbconn Instance = new KqProductsDbconn();
  10. #region 获取列表
  11. public List<KqProducts> GetList()
  12. {
  13. string key = "KqProducts";
  14. List<KqProducts> list = new List<KqProducts>();
  15. if (RedisDbconn.Instance.Exists(key))
  16. {
  17. list = RedisDbconn.Instance.GetList<KqProducts>(key, 1, 100);
  18. if (list.Count > 0)
  19. {
  20. return list;
  21. }
  22. }
  23. List<KqProducts> newlist = new List<KqProducts>();
  24. RedisDbconn.Instance.GetLock(key + ":lock");
  25. WebCMSEntities db = new WebCMSEntities();
  26. var mysqllist = db.KqProducts.Where(m => m.Status == 1).OrderBy(m => m.Id).ToList();
  27. if (mysqllist.Count > 0)
  28. {
  29. foreach (var sub in mysqllist)
  30. {
  31. newlist.Add(sub);
  32. }
  33. RedisDbconn.Instance.Clear(key);
  34. foreach (KqProducts sub in newlist)
  35. {
  36. RedisDbconn.Instance.AddRightList(key, sub);
  37. }
  38. }
  39. db.Dispose();
  40. RedisDbconn.Instance.ReleaseLock(key + ":lock");
  41. return newlist;
  42. }
  43. #endregion
  44. }
  45. }