// Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT. /* Package kfc is a generated mc cache package. It is generated from: type _mc interface { // mc: -key=kfcKey CacheKfcCoupon(c context.Context, id int64) (*kfc.BnjKfcCoupon, error) // mc: -key=kfcKey -expire=d.mcKfcExpire -encode=pb AddCacheKfcCoupon(c context.Context, id int64, val *kfc.BnjKfcCoupon) error // mc: -key=kfcKey DelCacheKfcCoupon(c context.Context, id int64) error // mc: -key=kfcCodeKey CacheKfcCode(c context.Context, code string) (int64, error) // mc: -key=kfcCodeKey -expire=d.mcKfcCodeExpire -encode=raw AddCacheKfcCode(c context.Context, code string, val int64) error } */ package kfc import ( "context" "fmt" "strconv" "go-common/app/interface/main/activity/model/kfc" "go-common/library/cache/memcache" "go-common/library/log" "go-common/library/stat/prom" ) var _ _mc // CacheKfcCoupon get data from mc func (d *Dao) CacheKfcCoupon(c context.Context, id int64) (res *kfc.BnjKfcCoupon, err error) { conn := d.mc.Get(c) defer conn.Close() key := kfcKey(id) reply, err := conn.Get(key) if err != nil { if err == memcache.ErrNotFound { err = nil return } prom.BusinessErrCount.Incr("mc:CacheKfcCoupon") log.Errorv(c, log.KV("CacheKfcCoupon", fmt.Sprintf("%+v", err)), log.KV("key", key)) return } res = &kfc.BnjKfcCoupon{} err = conn.Scan(reply, res) if err != nil { prom.BusinessErrCount.Incr("mc:CacheKfcCoupon") log.Errorv(c, log.KV("CacheKfcCoupon", fmt.Sprintf("%+v", err)), log.KV("key", key)) return } return } // AddCacheKfcCoupon Set data to mc func (d *Dao) AddCacheKfcCoupon(c context.Context, id int64, val *kfc.BnjKfcCoupon) (err error) { if val == nil { return } conn := d.mc.Get(c) defer conn.Close() key := kfcKey(id) item := &memcache.Item{Key: key, Object: val, Expiration: d.mcKfcExpire, Flags: memcache.FlagProtobuf} if err = conn.Set(item); err != nil { prom.BusinessErrCount.Incr("mc:AddCacheKfcCoupon") log.Errorv(c, log.KV("AddCacheKfcCoupon", fmt.Sprintf("%+v", err)), log.KV("key", key)) return } return } // DelCacheKfcCoupon delete data from mc func (d *Dao) DelCacheKfcCoupon(c context.Context, id int64) (err error) { conn := d.mc.Get(c) defer conn.Close() key := kfcKey(id) if err = conn.Delete(key); err != nil { if err == memcache.ErrNotFound { err = nil return } prom.BusinessErrCount.Incr("mc:DelCacheKfcCoupon") log.Errorv(c, log.KV("DelCacheKfcCoupon", fmt.Sprintf("%+v", err)), log.KV("key", key)) return } return } // CacheKfcCode get data from mc func (d *Dao) CacheKfcCode(c context.Context, id string) (res int64, err error) { conn := d.mc.Get(c) defer conn.Close() key := kfcCodeKey(id) reply, err := conn.Get(key) if err != nil { if err == memcache.ErrNotFound { err = nil return } prom.BusinessErrCount.Incr("mc:CacheKfcCode") log.Errorv(c, log.KV("CacheKfcCode", fmt.Sprintf("%+v", err)), log.KV("key", key)) return } var v string err = conn.Scan(reply, &v) if err != nil { prom.BusinessErrCount.Incr("mc:CacheKfcCode") log.Errorv(c, log.KV("CacheKfcCode", fmt.Sprintf("%+v", err)), log.KV("key", key)) return } r, err := strconv.ParseInt(v, 10, 64) if err != nil { prom.BusinessErrCount.Incr("mc:CacheKfcCode") log.Errorv(c, log.KV("CacheKfcCode", fmt.Sprintf("%+v", err)), log.KV("key", key)) return } res = int64(r) return } // AddCacheKfcCode Set data to mc func (d *Dao) AddCacheKfcCode(c context.Context, id string, val int64) (err error) { conn := d.mc.Get(c) defer conn.Close() key := kfcCodeKey(id) bs := []byte(strconv.FormatInt(int64(val), 10)) item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcKfcCodeExpire, Flags: memcache.FlagRAW} if err = conn.Set(item); err != nil { prom.BusinessErrCount.Incr("mc:AddCacheKfcCode") log.Errorv(c, log.KV("AddCacheKfcCode", fmt.Sprintf("%+v", err)), log.KV("key", key)) return } return }