123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894 |
- // Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
- /*
- Package like is a generated mc cache package.
- It is generated from:
- type _mc interface {
- // mc: -key=likeKey
- CacheLike(c context.Context, id int64) (*likemdl.Item, error)
- // mc: -key=likeKey
- CacheLikes(c context.Context, id []int64) (map[int64]*likemdl.Item, error)
- // mc: -key=likeKey -expire=d.mcPerpetualExpire -encode=json
- AddCacheLikes(c context.Context, items map[int64]*likemdl.Item) error
- // mc: -key=likeKey -expire=d.mcPerpetualExpire -encode=json
- AddCacheLike(c context.Context, key int64, value *likemdl.Item) error
- // mc: -key=actSubjectKey
- CacheActSubject(c context.Context, id int64) (*likemdl.SubjectItem, error)
- // mc: -key=actSubjectKey -expire=d.mcPerpetualExpire -encode=pb
- AddCacheActSubject(c context.Context, key int64, value *likemdl.SubjectItem) error
- // mc: -key=actSubjectMaxIDKey
- CacheActSubjectMaxID(c context.Context) (res int64, err error)
- // mc: -key=actSubjectMaxIDKey -expire=d.mcPerpetualExpire -encode=raw
- AddCacheActSubjectMaxID(c context.Context, sid int64) error
- // mc: -key=likeMaxIDKey
- CacheLikeMaxID(c context.Context) (res int64, err error)
- // mc: -key=likeMaxIDKey -expire=d.mcPerpetualExpire -encode=raw
- AddCacheLikeMaxID(c context.Context, lid int64) error
- //mc: -key=likeMissionBuffKey
- CacheLikeMissionBuff(c context.Context, sid int64, mid int64) (res int64, err error)
- //mc: -key=likeMissionBuffKey
- AddCacheLikeMissionBuff(c context.Context, sid int64, val int64, mid int64) error
- //mc: -key=likeMissionGroupIDkey
- CacheMissionGroupItems(ctx context.Context, lids []int64) (map[int64]*likemdl.MissionGroup, error)
- //mc: -key=likeMissionGroupIDkey -expire=d.mcItemExpire -encode=pb
- AddCacheMissionGroupItems(ctx context.Context, val map[int64]*likemdl.MissionGroup) error
- //mc: -key=likeActMissionKey
- CacheActMission(c context.Context, sid int64, lid int64, mid int64) (res int64, err error)
- //mc: -key=likeActMissionKey -expire=d.mcPerpetualExpire -encode=raw
- AddCacheActMission(c context.Context, sid int64, val int64, lid int64, mid int64) error
- //mc: -key=actAchieveKey
- CacheActLikeAchieves(c context.Context, sid int64) (res *likemdl.Achievements, err error)
- //mc: -key=actAchieveKey -expire=d.mcItemExpire -encode=pb
- AddCacheActLikeAchieves(c context.Context, sid int64, res *likemdl.Achievements) error
- //mc: -key=actMissionFriendsKey
- CacheActMissionFriends(c context.Context, sid int64, lid int64) (res *likemdl.ActMissionGroups, err error)
- //mc: -key=actMissionFriendsKey
- DelCacheActMissionFriends(c context.Context, sid int64, lid int64) error
- //mc: -key=actMissionFriendsKey -expire=d.mcItemExpire -encode=pb
- AddCacheActMissionFriends(c context.Context, sid int64, res *likemdl.ActMissionGroups, lid int64) error
- //mc: -key=actUserAchieveKey
- CacheActUserAchieve(c context.Context, id int64) (res *likemdl.ActLikeUserAchievement, err error)
- //mc: -key=actUserAchieveKey -expire=d.mcItemExpire -encode=pb
- AddCacheActUserAchieve(c context.Context, id int64, val *likemdl.ActLikeUserAchievement) error
- //mc: -key=actUserAchieveAwardKey
- CacheActUserAward(c context.Context, id int64) (res int64, err error)
- //mc: -key=actUserAchieveAwardKey -expire=d.mcPerpetualExpire -encode=raw
- AddCacheActUserAward(c context.Context, id int64, val int64) error
- // mc: -key=subjectStatKey
- CacheSubjectStat(c context.Context, sid int64) (*likemdl.SubjectStat, error)
- // mc: -key=subjectStatKey -expire=d.mcSubStatExpire -encode=json
- AddCacheSubjectStat(c context.Context, sid int64, value *likemdl.SubjectStat) error
- // mc: -key=viewRankKey
- CacheViewRank(c context.Context, sid int64) (string, error)
- // mc: -key=viewRankKey -expire=d.mcViewRankExpire -encode=raw
- AddCacheViewRank(c context.Context, sid int64, value string) error
- // mc: -key=likeContentKey
- CacheLikeContent(c context.Context, lids []int64) (res map[int64]*likemdl.LikeContent, err error)
- // mc: -key=likeContentKey -expire=d.mcPerpetualExpire -encode=pb
- AddCacheLikeContent(c context.Context, val map[int64]*likemdl.LikeContent) error
- // mc: -key=sourceItemKey
- CacheSourceItemData(c context.Context, sid int64) ([]int64, error)
- // mc: -key=sourceItemKey -expire=d.mcSourceItemExpire -encode=json
- AddCacheSourceItemData(c context.Context, sid int64, lids []int64) error
- // mc: -key=subjectProtocolKey
- CacheActSubjectProtocol(c context.Context, sid int64) (res *likemdl.ActSubjectProtocol, err error)
- // mc: -key=subjectProtocolKey -expire=d.mcProtocolExpire -encode=pb
- AddCacheActSubjectProtocol(c context.Context, sid int64, value *likemdl.ActSubjectProtocol) error
- }
- */
- package like
- import (
- "context"
- "fmt"
- "strconv"
- likemdl "go-common/app/interface/main/activity/model/like"
- "go-common/library/cache/memcache"
- "go-common/library/log"
- "go-common/library/stat/prom"
- )
- var _ _mc
- // CacheLike get data from mc
- func (d *Dao) CacheLike(c context.Context, id int64) (res *likemdl.Item, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := likeKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheLike")
- log.Errorv(c, log.KV("CacheLike", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &likemdl.Item{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheLike")
- log.Errorv(c, log.KV("CacheLike", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheLikes get data from mc
- func (d *Dao) CacheLikes(c context.Context, ids []int64) (res map[int64]*likemdl.Item, err error) {
- l := len(ids)
- if l == 0 {
- return
- }
- keysMap := make(map[string]int64, l)
- keys := make([]string, 0, l)
- for _, id := range ids {
- key := likeKey(id)
- keysMap[key] = id
- keys = append(keys, key)
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- replies, err := conn.GetMulti(keys)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheLikes")
- log.Errorv(c, log.KV("CacheLikes", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
- return
- }
- for key, reply := range replies {
- var v *likemdl.Item
- v = &likemdl.Item{}
- err = conn.Scan(reply, v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheLikes")
- log.Errorv(c, log.KV("CacheLikes", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- if res == nil {
- res = make(map[int64]*likemdl.Item, len(keys))
- }
- res[keysMap[key]] = v
- }
- return
- }
- // AddCacheLikes Set data to mc
- func (d *Dao) AddCacheLikes(c context.Context, values map[int64]*likemdl.Item) (err error) {
- if len(values) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- for id, val := range values {
- key := likeKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcPerpetualExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheLikes")
- log.Errorv(c, log.KV("AddCacheLikes", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- }
- return
- }
- // AddCacheLike Set data to mc
- func (d *Dao) AddCacheLike(c context.Context, id int64, val *likemdl.Item) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := likeKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcPerpetualExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheLike")
- log.Errorv(c, log.KV("AddCacheLike", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheActSubject get data from mc
- func (d *Dao) CacheActSubject(c context.Context, id int64) (res *likemdl.SubjectItem, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actSubjectKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheActSubject")
- log.Errorv(c, log.KV("CacheActSubject", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &likemdl.SubjectItem{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActSubject")
- log.Errorv(c, log.KV("CacheActSubject", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheActSubject Set data to mc
- func (d *Dao) AddCacheActSubject(c context.Context, id int64, val *likemdl.SubjectItem) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actSubjectKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcPerpetualExpire, Flags: memcache.FlagProtobuf}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheActSubject")
- log.Errorv(c, log.KV("AddCacheActSubject", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheActSubjectMaxID get data from mc
- func (d *Dao) CacheActSubjectMaxID(c context.Context) (res int64, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actSubjectMaxIDKey()
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheActSubjectMaxID")
- log.Errorv(c, log.KV("CacheActSubjectMaxID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- var v string
- err = conn.Scan(reply, &v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActSubjectMaxID")
- log.Errorv(c, log.KV("CacheActSubjectMaxID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- r, err := strconv.ParseInt(v, 10, 64)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActSubjectMaxID")
- log.Errorv(c, log.KV("CacheActSubjectMaxID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = int64(r)
- return
- }
- // AddCacheActSubjectMaxID Set data to mc
- func (d *Dao) AddCacheActSubjectMaxID(c context.Context, val int64) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actSubjectMaxIDKey()
- bs := []byte(strconv.FormatInt(int64(val), 10))
- item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcPerpetualExpire, Flags: memcache.FlagRAW}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheActSubjectMaxID")
- log.Errorv(c, log.KV("AddCacheActSubjectMaxID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheLikeMaxID get data from mc
- func (d *Dao) CacheLikeMaxID(c context.Context) (res int64, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := likeMaxIDKey()
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheLikeMaxID")
- log.Errorv(c, log.KV("CacheLikeMaxID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- var v string
- err = conn.Scan(reply, &v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheLikeMaxID")
- log.Errorv(c, log.KV("CacheLikeMaxID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- r, err := strconv.ParseInt(v, 10, 64)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheLikeMaxID")
- log.Errorv(c, log.KV("CacheLikeMaxID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = int64(r)
- return
- }
- // AddCacheLikeMaxID Set data to mc
- func (d *Dao) AddCacheLikeMaxID(c context.Context, val int64) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := likeMaxIDKey()
- bs := []byte(strconv.FormatInt(int64(val), 10))
- item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcPerpetualExpire, Flags: memcache.FlagRAW}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheLikeMaxID")
- log.Errorv(c, log.KV("AddCacheLikeMaxID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheLikeMissionBuff get data from mc
- func (d *Dao) CacheLikeMissionBuff(c context.Context, id int64, mid int64) (res int64, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := likeMissionBuffKey(id, mid)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheLikeMissionBuff")
- log.Errorv(c, log.KV("CacheLikeMissionBuff", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- var v string
- err = conn.Scan(reply, &v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheLikeMissionBuff")
- log.Errorv(c, log.KV("CacheLikeMissionBuff", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- r, err := strconv.ParseInt(v, 10, 64)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheLikeMissionBuff")
- log.Errorv(c, log.KV("CacheLikeMissionBuff", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = int64(r)
- return
- }
- // AddCacheLikeMissionBuff Set data to mc
- func (d *Dao) AddCacheLikeMissionBuff(c context.Context, id int64, val int64, mid int64) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := likeMissionBuffKey(id, mid)
- bs := []byte(strconv.FormatInt(int64(val), 10))
- item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcPerpetualExpire, Flags: memcache.FlagRAW}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheLikeMissionBuff")
- log.Errorv(c, log.KV("AddCacheLikeMissionBuff", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheMissionGroupItems get data from mc
- func (d *Dao) CacheMissionGroupItems(c context.Context, ids []int64) (res map[int64]*likemdl.MissionGroup, err error) {
- l := len(ids)
- if l == 0 {
- return
- }
- keysMap := make(map[string]int64, l)
- keys := make([]string, 0, l)
- for _, id := range ids {
- key := likeMissionGroupIDkey(id)
- keysMap[key] = id
- keys = append(keys, key)
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- replies, err := conn.GetMulti(keys)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheMissionGroupItems")
- log.Errorv(c, log.KV("CacheMissionGroupItems", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
- return
- }
- for key, reply := range replies {
- var v *likemdl.MissionGroup
- v = &likemdl.MissionGroup{}
- err = conn.Scan(reply, v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheMissionGroupItems")
- log.Errorv(c, log.KV("CacheMissionGroupItems", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- if res == nil {
- res = make(map[int64]*likemdl.MissionGroup, len(keys))
- }
- res[keysMap[key]] = v
- }
- return
- }
- // AddCacheMissionGroupItems Set data to mc
- func (d *Dao) AddCacheMissionGroupItems(c context.Context, values map[int64]*likemdl.MissionGroup) (err error) {
- if len(values) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- for id, val := range values {
- key := likeMissionGroupIDkey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcItemExpire, Flags: memcache.FlagProtobuf}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheMissionGroupItems")
- log.Errorv(c, log.KV("AddCacheMissionGroupItems", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- }
- return
- }
- // CacheActMission get data from mc
- func (d *Dao) CacheActMission(c context.Context, id int64, lid int64, mid int64) (res int64, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := likeActMissionKey(id, lid, mid)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheActMission")
- log.Errorv(c, log.KV("CacheActMission", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- var v string
- err = conn.Scan(reply, &v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActMission")
- log.Errorv(c, log.KV("CacheActMission", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- r, err := strconv.ParseInt(v, 10, 64)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActMission")
- log.Errorv(c, log.KV("CacheActMission", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = int64(r)
- return
- }
- // AddCacheActMission Set data to mc
- func (d *Dao) AddCacheActMission(c context.Context, id int64, val int64, lid int64, mid int64) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := likeActMissionKey(id, lid, mid)
- bs := []byte(strconv.FormatInt(int64(val), 10))
- item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcPerpetualExpire, Flags: memcache.FlagRAW}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheActMission")
- log.Errorv(c, log.KV("AddCacheActMission", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheActLikeAchieves get data from mc
- func (d *Dao) CacheActLikeAchieves(c context.Context, id int64) (res *likemdl.Achievements, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actAchieveKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheActLikeAchieves")
- log.Errorv(c, log.KV("CacheActLikeAchieves", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &likemdl.Achievements{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActLikeAchieves")
- log.Errorv(c, log.KV("CacheActLikeAchieves", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheActLikeAchieves Set data to mc
- func (d *Dao) AddCacheActLikeAchieves(c context.Context, id int64, val *likemdl.Achievements) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actAchieveKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcItemExpire, Flags: memcache.FlagProtobuf}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheActLikeAchieves")
- log.Errorv(c, log.KV("AddCacheActLikeAchieves", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheActMissionFriends get data from mc
- func (d *Dao) CacheActMissionFriends(c context.Context, id int64, lid int64) (res *likemdl.ActMissionGroups, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actMissionFriendsKey(id, lid)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheActMissionFriends")
- log.Errorv(c, log.KV("CacheActMissionFriends", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &likemdl.ActMissionGroups{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActMissionFriends")
- log.Errorv(c, log.KV("CacheActMissionFriends", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // DelCacheActMissionFriends delete data from mc
- func (d *Dao) DelCacheActMissionFriends(c context.Context, id int64, lid int64) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actMissionFriendsKey(id, lid)
- if err = conn.Delete(key); err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:DelCacheActMissionFriends")
- log.Errorv(c, log.KV("DelCacheActMissionFriends", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheActMissionFriends Set data to mc
- func (d *Dao) AddCacheActMissionFriends(c context.Context, id int64, val *likemdl.ActMissionGroups, lid int64) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actMissionFriendsKey(id, lid)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcItemExpire, Flags: memcache.FlagProtobuf}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheActMissionFriends")
- log.Errorv(c, log.KV("AddCacheActMissionFriends", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheActUserAchieve get data from mc
- func (d *Dao) CacheActUserAchieve(c context.Context, id int64) (res *likemdl.ActLikeUserAchievement, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actUserAchieveKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheActUserAchieve")
- log.Errorv(c, log.KV("CacheActUserAchieve", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &likemdl.ActLikeUserAchievement{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActUserAchieve")
- log.Errorv(c, log.KV("CacheActUserAchieve", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheActUserAchieve Set data to mc
- func (d *Dao) AddCacheActUserAchieve(c context.Context, id int64, val *likemdl.ActLikeUserAchievement) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actUserAchieveKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcItemExpire, Flags: memcache.FlagProtobuf}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheActUserAchieve")
- log.Errorv(c, log.KV("AddCacheActUserAchieve", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheActUserAward get data from mc
- func (d *Dao) CacheActUserAward(c context.Context, id int64) (res int64, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actUserAchieveAwardKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheActUserAward")
- log.Errorv(c, log.KV("CacheActUserAward", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- var v string
- err = conn.Scan(reply, &v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActUserAward")
- log.Errorv(c, log.KV("CacheActUserAward", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- r, err := strconv.ParseInt(v, 10, 64)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActUserAward")
- log.Errorv(c, log.KV("CacheActUserAward", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = int64(r)
- return
- }
- // AddCacheActUserAward Set data to mc
- func (d *Dao) AddCacheActUserAward(c context.Context, id int64, val int64) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := actUserAchieveAwardKey(id)
- bs := []byte(strconv.FormatInt(int64(val), 10))
- item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcPerpetualExpire, Flags: memcache.FlagRAW}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheActUserAward")
- log.Errorv(c, log.KV("AddCacheActUserAward", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheSubjectStat get data from mc
- func (d *Dao) CacheSubjectStat(c context.Context, id int64) (res *likemdl.SubjectStat, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := subjectStatKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheSubjectStat")
- log.Errorv(c, log.KV("CacheSubjectStat", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &likemdl.SubjectStat{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheSubjectStat")
- log.Errorv(c, log.KV("CacheSubjectStat", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheSubjectStat Set data to mc
- func (d *Dao) AddCacheSubjectStat(c context.Context, id int64, val *likemdl.SubjectStat) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := subjectStatKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcSubStatExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheSubjectStat")
- log.Errorv(c, log.KV("AddCacheSubjectStat", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheViewRank get data from mc
- func (d *Dao) CacheViewRank(c context.Context, id int64) (res string, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := viewRankKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheViewRank")
- log.Errorv(c, log.KV("CacheViewRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- err = conn.Scan(reply, &res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheViewRank")
- log.Errorv(c, log.KV("CacheViewRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheViewRank Set data to mc
- func (d *Dao) AddCacheViewRank(c context.Context, id int64, val string) (err error) {
- if len(val) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := viewRankKey(id)
- bs := []byte(val)
- item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcViewRankExpire, Flags: memcache.FlagRAW}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheViewRank")
- log.Errorv(c, log.KV("AddCacheViewRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheLikeContent get data from mc
- func (d *Dao) CacheLikeContent(c context.Context, ids []int64) (res map[int64]*likemdl.LikeContent, err error) {
- l := len(ids)
- if l == 0 {
- return
- }
- keysMap := make(map[string]int64, l)
- keys := make([]string, 0, l)
- for _, id := range ids {
- key := likeContentKey(id)
- keysMap[key] = id
- keys = append(keys, key)
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- replies, err := conn.GetMulti(keys)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheLikeContent")
- log.Errorv(c, log.KV("CacheLikeContent", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
- return
- }
- for key, reply := range replies {
- var v *likemdl.LikeContent
- v = &likemdl.LikeContent{}
- err = conn.Scan(reply, v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheLikeContent")
- log.Errorv(c, log.KV("CacheLikeContent", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- if res == nil {
- res = make(map[int64]*likemdl.LikeContent, len(keys))
- }
- res[keysMap[key]] = v
- }
- return
- }
- // AddCacheLikeContent Set data to mc
- func (d *Dao) AddCacheLikeContent(c context.Context, values map[int64]*likemdl.LikeContent) (err error) {
- if len(values) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- for id, val := range values {
- key := likeContentKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcPerpetualExpire, Flags: memcache.FlagProtobuf}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheLikeContent")
- log.Errorv(c, log.KV("AddCacheLikeContent", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- }
- return
- }
- // CacheSourceItemData get data from mc
- func (d *Dao) CacheSourceItemData(c context.Context, id int64) (res []int64, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := sourceItemKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheSourceItemData")
- log.Errorv(c, log.KV("CacheSourceItemData", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = []int64{}
- err = conn.Scan(reply, &res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheSourceItemData")
- log.Errorv(c, log.KV("CacheSourceItemData", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheSourceItemData Set data to mc
- func (d *Dao) AddCacheSourceItemData(c context.Context, id int64, val []int64) (err error) {
- if len(val) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := sourceItemKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcSourceItemExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheSourceItemData")
- log.Errorv(c, log.KV("AddCacheSourceItemData", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheActSubjectProtocol get data from mc
- func (d *Dao) CacheActSubjectProtocol(c context.Context, id int64) (res *likemdl.ActSubjectProtocol, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := subjectProtocolKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheActSubjectProtocol")
- log.Errorv(c, log.KV("CacheActSubjectProtocol", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &likemdl.ActSubjectProtocol{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheActSubjectProtocol")
- log.Errorv(c, log.KV("CacheActSubjectProtocol", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheActSubjectProtocol Set data to mc
- func (d *Dao) AddCacheActSubjectProtocol(c context.Context, id int64, val *likemdl.ActSubjectProtocol) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := subjectProtocolKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcProtocolExpire, Flags: memcache.FlagProtobuf}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheActSubjectProtocol")
- log.Errorv(c, log.KV("AddCacheActSubjectProtocol", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
|