go-common/app/interface/main/activity/dao/bws/mc.cache.go

283 lines
8.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 bws is a generated mc cache package.
It is generated from:
type _mc interface {
//mc: -key=midKey
CacheUsersMid(c context.Context, key int64) (*bwsmdl.Users, error)
//mc: -key=midKey -expire=d.mcExpire -encode=pb
AddCacheUsersMid(c context.Context, key int64, value *bwsmdl.Users) error
//mc: -key=midKey
DelCacheUsersMid(c context.Context, key int64) error
//mc: -key=keyKey
CacheUsersKey(c context.Context, key string) (*bwsmdl.Users, error)
//mc: -key=keyKey -expire=d.mcExpire -encode=pb
AddCacheUsersKey(c context.Context, key string, value *bwsmdl.Users) error
//mc: -key=keyKey
DelCacheUsersKey(c context.Context, key string) error
//mc: -key=pointsKey
CachePoints(c context.Context, key int64) (*bwsmdl.Points, error)
//mc: -key=pointsKey -expire=d.mcExpire -encode=pb
AddCachePoints(c context.Context, key int64, value *bwsmdl.Points) error
//mc: -key=pointsKey
DelCachePoints(c context.Context, key int64) error
//mc: -key=achievesKey
CacheAchievements(c context.Context, key int64) (*bwsmdl.Achievements, error)
//mc: -key=achievesKey -expire=d.mcExpire -encode=pb
AddCacheAchievements(c context.Context, key int64, value *bwsmdl.Achievements) error
//mc: -key=achievesKey
DelCacheAchievements(c context.Context, key int64) error
}
*/
package bws
import (
"context"
"fmt"
bwsmdl "go-common/app/interface/main/activity/model/bws"
"go-common/library/cache/memcache"
"go-common/library/log"
"go-common/library/stat/prom"
)
var _ _mc
// CacheUsersMid get data from mc
func (d *Dao) CacheUsersMid(c context.Context, id int64) (res *bwsmdl.Users, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := midKey(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheUsersMid")
log.Errorv(c, log.KV("CacheUsersMid", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &bwsmdl.Users{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUsersMid")
log.Errorv(c, log.KV("CacheUsersMid", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheUsersMid Set data to mc
func (d *Dao) AddCacheUsersMid(c context.Context, id int64, val *bwsmdl.Users) (err error) {
if val == nil {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := midKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.mcExpire, Flags: memcache.FlagProtobuf}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheUsersMid")
log.Errorv(c, log.KV("AddCacheUsersMid", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// DelCacheUsersMid delete data from mc
func (d *Dao) DelCacheUsersMid(c context.Context, id int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := midKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCacheUsersMid")
log.Errorv(c, log.KV("DelCacheUsersMid", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// CacheUsersKey get data from mc
func (d *Dao) CacheUsersKey(c context.Context, id string) (res *bwsmdl.Users, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := keyKey(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheUsersKey")
log.Errorv(c, log.KV("CacheUsersKey", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &bwsmdl.Users{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUsersKey")
log.Errorv(c, log.KV("CacheUsersKey", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheUsersKey Set data to mc
func (d *Dao) AddCacheUsersKey(c context.Context, id string, val *bwsmdl.Users) (err error) {
if val == nil {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := keyKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.mcExpire, Flags: memcache.FlagProtobuf}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheUsersKey")
log.Errorv(c, log.KV("AddCacheUsersKey", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// DelCacheUsersKey delete data from mc
func (d *Dao) DelCacheUsersKey(c context.Context, id string) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := keyKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCacheUsersKey")
log.Errorv(c, log.KV("DelCacheUsersKey", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// CachePoints get data from mc
func (d *Dao) CachePoints(c context.Context, id int64) (res *bwsmdl.Points, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := pointsKey(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CachePoints")
log.Errorv(c, log.KV("CachePoints", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &bwsmdl.Points{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CachePoints")
log.Errorv(c, log.KV("CachePoints", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCachePoints Set data to mc
func (d *Dao) AddCachePoints(c context.Context, id int64, val *bwsmdl.Points) (err error) {
if val == nil {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := pointsKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.mcExpire, Flags: memcache.FlagProtobuf}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCachePoints")
log.Errorv(c, log.KV("AddCachePoints", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// DelCachePoints delete data from mc
func (d *Dao) DelCachePoints(c context.Context, id int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := pointsKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCachePoints")
log.Errorv(c, log.KV("DelCachePoints", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// CacheAchievements get data from mc
func (d *Dao) CacheAchievements(c context.Context, id int64) (res *bwsmdl.Achievements, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := achievesKey(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheAchievements")
log.Errorv(c, log.KV("CacheAchievements", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &bwsmdl.Achievements{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheAchievements")
log.Errorv(c, log.KV("CacheAchievements", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheAchievements Set data to mc
func (d *Dao) AddCacheAchievements(c context.Context, id int64, val *bwsmdl.Achievements) (err error) {
if val == nil {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := achievesKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.mcExpire, Flags: memcache.FlagProtobuf}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheAchievements")
log.Errorv(c, log.KV("AddCacheAchievements", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// DelCacheAchievements delete data from mc
func (d *Dao) DelCacheAchievements(c context.Context, id int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := achievesKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCacheAchievements")
log.Errorv(c, log.KV("DelCacheAchievements", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}