mc.cache.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
  2. /*
  3. Package anchorReward is a generated mc cache package.
  4. It is generated from:
  5. type _mc interface {
  6. // 获取奖励配置
  7. // mc: -key=keyRewardConf
  8. CacheRewardConf(c context.Context, id int64) (*model.AnchorRewardConf, error)
  9. // 保存奖励配置
  10. // mc: -key=keyRewardConf -expire=d.keyRewardConfExpire -encode=json|gzip
  11. AddCacheRewardConf(c context.Context, id int64, value *model.AnchorRewardConf) error
  12. }
  13. */
  14. package anchorReward
  15. import (
  16. "context"
  17. "fmt"
  18. model "go-common/app/service/live/xrewardcenter/model/anchorTask"
  19. "go-common/library/cache/memcache"
  20. "go-common/library/log"
  21. "go-common/library/stat/prom"
  22. )
  23. var _ _mc
  24. // CacheRewardConf 获取奖励配置
  25. func (d *Dao) CacheRewardConf(c context.Context, id int64) (res *model.AnchorRewardConf, err error) {
  26. conn := d.mc.Get(c)
  27. defer conn.Close()
  28. key := keyRewardConf(id)
  29. reply, err := conn.Get(key)
  30. if err != nil {
  31. if err == memcache.ErrNotFound {
  32. err = nil
  33. return
  34. }
  35. prom.BusinessErrCount.Incr("mc:CacheRewardConf")
  36. log.Errorv(c, log.KV("CacheRewardConf", fmt.Sprintf("%+v", err)), log.KV("key", key))
  37. return
  38. }
  39. res = &model.AnchorRewardConf{}
  40. err = conn.Scan(reply, res)
  41. if err != nil {
  42. prom.BusinessErrCount.Incr("mc:CacheRewardConf")
  43. log.Errorv(c, log.KV("CacheRewardConf", fmt.Sprintf("%+v", err)), log.KV("key", key))
  44. return
  45. }
  46. return
  47. }
  48. // AddCacheRewardConf 保存奖励配置
  49. func (d *Dao) AddCacheRewardConf(c context.Context, id int64, val *model.AnchorRewardConf) (err error) {
  50. if val == nil {
  51. return
  52. }
  53. conn := d.mc.Get(c)
  54. defer conn.Close()
  55. key := keyRewardConf(id)
  56. item := &memcache.Item{Key: key, Object: val, Expiration: d.keyRewardConfExpire, Flags: memcache.FlagJSON | memcache.FlagGzip}
  57. if err = conn.Set(item); err != nil {
  58. prom.BusinessErrCount.Incr("mc:AddCacheRewardConf")
  59. log.Errorv(c, log.KV("AddCacheRewardConf", fmt.Sprintf("%+v", err)), log.KV("key", key))
  60. return
  61. }
  62. return
  63. }