ConsumersDbconn.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.MainModels;
  5. namespace MySystem
  6. {
  7. public class ConsumersDbconn
  8. {
  9. public readonly static ConsumersDbconn Instance = new ConsumersDbconn();
  10. #region 获取单个字段
  11. public Consumers Get(int Id)
  12. {
  13. string key = "Consumers:" + Id;
  14. if (RedisDbconn.Instance.Exists(key))
  15. {
  16. Consumers obj = RedisDbconn.Instance.Get<Consumers>(key);
  17. if (obj != null)
  18. {
  19. return obj;
  20. }
  21. }
  22. WebCMSEntities db = new WebCMSEntities();
  23. Consumers order = db.Consumers.FirstOrDefault(m => m.Id == Id);
  24. if (order != null)
  25. {
  26. RedisDbconn.Instance.Set(key, order);
  27. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  28. }
  29. return order;
  30. }
  31. #endregion
  32. }
  33. }