memcache.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package up
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. gmc "go-common/library/cache/memcache"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _mcnSign = "mcn_s_"
  11. _mcnUpper = "mcn_upperm_%d_%d"
  12. )
  13. // user mcn sign key.
  14. func mcnSignKey(mcnMid int64) string {
  15. return _mcnSign + strconv.FormatInt(mcnMid, 10)
  16. }
  17. // user upper key.
  18. func mcnUpperKey(signID, upMid int64) string {
  19. return fmt.Sprintf(_mcnUpper, signID, upMid)
  20. }
  21. // DelMcnSignCache del mcn sign cache info.
  22. func (d *Dao) DelMcnSignCache(c context.Context, mcnMid int64) (err error) {
  23. conn := d.mc.Get(c)
  24. defer conn.Close()
  25. if err = conn.Delete(mcnSignKey(mcnMid)); err != nil {
  26. if err == gmc.ErrNotFound {
  27. err = nil
  28. return
  29. }
  30. log.Error("conn.Delete(%d) error(%v)", mcnMid, err)
  31. }
  32. return
  33. }
  34. // DelMcnUpperCache del mcn upper cache.
  35. func (d *Dao) DelMcnUpperCache(c context.Context, signID, upMid int64) (err error) {
  36. conn := d.mc.Get(c)
  37. defer conn.Close()
  38. if err = conn.Delete(mcnUpperKey(signID, upMid)); err != nil {
  39. if err == gmc.ErrNotFound {
  40. err = nil
  41. return
  42. }
  43. log.Error("conn.Delete(%d, %d) error(%v)", signID, upMid, err)
  44. }
  45. return
  46. }