search.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package search
  2. import (
  3. "context"
  4. "time"
  5. searchModel "go-common/app/admin/main/feed/model/search"
  6. "go-common/library/cache/memcache"
  7. )
  8. //SetSearchAuditStat set hot publish state to MC
  9. func (d *Dao) SetSearchAuditStat(c context.Context, key string, state bool) (err error) {
  10. var (
  11. conn memcache.Conn
  12. p searchModel.PublishState
  13. )
  14. p.Date = time.Now().Format("2006-01-02")
  15. p.State = state
  16. conn = d.MC.Get(c)
  17. defer conn.Close()
  18. itemJSON := &memcache.Item{
  19. Key: key,
  20. Flags: memcache.FlagJSON,
  21. Object: p,
  22. Expiration: 0,
  23. }
  24. if err = conn.Set(itemJSON); err != nil {
  25. return
  26. }
  27. return
  28. }
  29. //GetSearchAuditStat get hot publish state from MC
  30. func (d *Dao) GetSearchAuditStat(c context.Context, key string) (f bool, date string, err error) {
  31. var (
  32. conn memcache.Conn
  33. item *memcache.Item
  34. p searchModel.PublishState
  35. )
  36. conn = d.MC.Get(c)
  37. defer conn.Close()
  38. if item, err = conn.Get(key); err != nil {
  39. if err == memcache.ErrNotFound {
  40. return false, "", nil
  41. }
  42. return
  43. }
  44. if err = conn.Scan(item, &p); err != nil {
  45. return
  46. }
  47. return p.State, p.Date, nil
  48. }