mc_level.go 672 B

1234567891011121314151617181920212223242526272829303132333435
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/job/live-userexp/model"
  6. mc "go-common/library/cache/memcache"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _expKey = "level:%d"
  11. )
  12. func key(uid int64) string {
  13. return fmt.Sprintf(_expKey, uid)
  14. }
  15. // SetLevelCache 设置等级缓存
  16. func (d *Dao) SetLevelCache(c context.Context, level *model.Level) (err error) {
  17. key := key(level.Uid)
  18. conn := d.expMc.Get(c)
  19. defer conn.Close()
  20. if conn.Set(&mc.Item{
  21. Key: key,
  22. Object: level,
  23. Flags: mc.FlagProtobuf,
  24. Expiration: d.cacheExpire,
  25. }); err != nil {
  26. log.Error("[dao.mc_exp|SetLevelCache] conn.Set(%s, %v) error(%v)", key, level, err)
  27. }
  28. return
  29. }