mc.cache.go 888 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. mc "go-common/library/cache/memcache"
  7. "go-common/library/log"
  8. "go-common/library/stat/prom"
  9. )
  10. const (
  11. _prequip = "e_"
  12. )
  13. func equipKey(mid int64) string {
  14. return _prequip + strconv.FormatInt(mid, 10)
  15. }
  16. // pingMC ping memcache.
  17. func (d *Dao) pingMC(c context.Context) (err error) {
  18. conn := d.mc.Get(c)
  19. defer conn.Close()
  20. err = conn.Set(&mc.Item{
  21. Key: "ping",
  22. Value: []byte("pong"),
  23. })
  24. return
  25. }
  26. // DelCacheEquip delete data from mc
  27. func (d *Dao) DelCacheEquip(c context.Context, id int64) (err error) {
  28. conn := d.mc.Get(c)
  29. defer conn.Close()
  30. key := equipKey(id)
  31. if err = conn.Delete(key); err != nil {
  32. if err == mc.ErrNotFound {
  33. err = nil
  34. return
  35. }
  36. prom.BusinessErrCount.Incr("mc:DelCacheEquip")
  37. log.Errorv(c, log.KV("DelCacheEquip", fmt.Sprintf("%+v", err)), log.KV("key", key))
  38. return
  39. }
  40. return
  41. }