go-common/app/service/live/xrewardcenter/dao/anchorReward/mc.cache.go

72 lines
2.0 KiB
Go
Raw Normal View History

2019-04-22 10:49:16 +00:00
// Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
/*
Package anchorReward is a generated mc cache package.
It is generated from:
type _mc interface {
// 获取奖励配置
// mc: -key=keyRewardConf
CacheRewardConf(c context.Context, id int64) (*model.AnchorRewardConf, error)
// 保存奖励配置
// mc: -key=keyRewardConf -expire=d.keyRewardConfExpire -encode=json|gzip
AddCacheRewardConf(c context.Context, id int64, value *model.AnchorRewardConf) error
}
*/
package anchorReward
import (
"context"
"fmt"
model "go-common/app/service/live/xrewardcenter/model/anchorTask"
"go-common/library/cache/memcache"
"go-common/library/log"
"go-common/library/stat/prom"
)
var _ _mc
// CacheRewardConf 获取奖励配置
func (d *Dao) CacheRewardConf(c context.Context, id int64) (res *model.AnchorRewardConf, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := keyRewardConf(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheRewardConf")
log.Errorv(c, log.KV("CacheRewardConf", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &model.AnchorRewardConf{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheRewardConf")
log.Errorv(c, log.KV("CacheRewardConf", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheRewardConf 保存奖励配置
func (d *Dao) AddCacheRewardConf(c context.Context, id int64, val *model.AnchorRewardConf) (err error) {
if val == nil {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := keyRewardConf(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.keyRewardConfExpire, Flags: memcache.FlagJSON | memcache.FlagGzip}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheRewardConf")
log.Errorv(c, log.KV("AddCacheRewardConf", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}