sear_inter.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package dao
  2. import (
  3. "encoding/json"
  4. "context"
  5. "go-common/app/admin/main/tv/model"
  6. "go-common/library/cache/memcache"
  7. )
  8. //SiMcOutKey is used for tv search intervene key with MC
  9. const SiMcOutKey = "_tv_search"
  10. //SiMcStateKey is used for tv search intervene publish status key with MC
  11. const SiMcStateKey = "_tv_search_state"
  12. // SetSearchInterv is used for setting search inter rank cache
  13. func (d *Dao) SetSearchInterv(c context.Context, rank []*model.OutSearchInter) (err error) {
  14. var (
  15. conn memcache.Conn
  16. item *memcache.Item
  17. bs []byte
  18. )
  19. bs, err = json.Marshal(rank)
  20. if err != nil {
  21. return
  22. }
  23. conn = d.mc.Get(c)
  24. defer conn.Close()
  25. item = &memcache.Item{
  26. Key: SiMcOutKey,
  27. Value: bs,
  28. Expiration: 0,
  29. }
  30. err = conn.Set(item)
  31. return
  32. }
  33. // GetSearchInterv is used for getting search inter rank cache
  34. func (d *Dao) GetSearchInterv(c context.Context) (rank []*model.OutSearchInter, err error) {
  35. var (
  36. conn memcache.Conn
  37. item *memcache.Item
  38. )
  39. conn = d.mc.Get(c)
  40. defer conn.Close()
  41. if item, err = conn.Get(SiMcOutKey); err != nil {
  42. return
  43. }
  44. if err = json.Unmarshal(item.Value, &rank); err != nil {
  45. return
  46. }
  47. return
  48. }
  49. // SetPublishCache is used for setting publish status
  50. func (d *Dao) SetPublishCache(c context.Context, state *model.PublishStatus) (err error) {
  51. var (
  52. conn memcache.Conn
  53. item *memcache.Item
  54. bs []byte
  55. )
  56. bs, err = json.Marshal(state)
  57. if err != nil {
  58. return
  59. }
  60. conn = d.mc.Get(c)
  61. defer conn.Close()
  62. item = &memcache.Item{
  63. Key: SiMcStateKey,
  64. Value: bs,
  65. Expiration: 0,
  66. }
  67. err = conn.Set(item)
  68. return
  69. }
  70. // GetPublishCache is used for getting search inter rank cache
  71. func (d *Dao) GetPublishCache(c context.Context) (state *model.PublishStatus, err error) {
  72. var (
  73. conn memcache.Conn
  74. item *memcache.Item
  75. )
  76. conn = d.mc.Get(c)
  77. defer conn.Close()
  78. if item, err = conn.Get(SiMcStateKey); err != nil {
  79. return
  80. }
  81. if err = json.Unmarshal(item.Value, &state); err != nil {
  82. return
  83. }
  84. return
  85. }