UserLevelSetDbconn.cs 1.5 KB

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