123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867 |
- // Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
- /*
- Package dao is a generated mc cache package.
- It is generated from:
- type _mc interface {
- // 获取文集文章列表缓存
- //mc: -key=listArtsKey
- CacheListArts(c context.Context, id int64) (res []*model.ListArtMeta, err error)
- // 增加文集含有的文章列表缓存
- //mc: -key=listArtsKey -expire=d.mcListArtsExpire
- AddCacheListArts(c context.Context, id int64, arts []*model.ListArtMeta) (err error)
- // 获取文章所属文集
- //mc: -key=articleListKey -type=get
- ArticleListCache(c context.Context, id int64) (res int64, err error)
- // 增加文章所属文集缓存
- //mc: -key=articleListKey -expire=d.mcArtListExpire
- SetArticlesListCache(c context.Context, arts map[int64]int64) (err error)
- //mc: -key=listKey
- CacheList(c context.Context, id int64) (res *model.List, err error)
- //mc: -key=listKey -expire=d.mcListExpire
- AddCacheList(c context.Context, id int64, list *model.List) (err error)
- //mc: -key=listKey
- CacheLists(c context.Context, ids []int64) (res map[int64]*model.List, err error)
- //mc: -key=listKey -expire=d.mcListExpire
- AddCacheLists(c context.Context, lists map[int64]*model.List) (err error)
- //mc: -key=listArtsKey
- CacheListsArts(c context.Context, ids []int64) (res map[int64][]*model.ListArtMeta, err error)
- //mc: -key=listArtsKey -expire=d.mcListArtsExpire
- AddCacheListsArts(c context.Context, arts map[int64][]*model.ListArtMeta) (err error)
- //mc: -key=articleListKey
- CacheArtsListID(c context.Context, ids []int64) (res map[int64]int64, err error)
- //mc: -key=articleListKey -expire=d.mcArtListExpire
- AddCacheArtsListID(c context.Context, arts map[int64]int64) (err error)
- //mc: -key=upListsKey -expire=d.mcUpListsExpire
- AddCacheUpLists(c context.Context, mid int64, lists []int64) (err error)
- //mc: -key=upListsKey
- CacheUpLists(c context.Context, id int64) (res []int64, err error)
- //mc: -key=listReadCountKey -expire=d.mcListReadExpire
- AddCacheListReadCount(c context.Context, id int64, read int64) (err error)
- //mc: -key=listReadCountKey
- CacheListReadCount(c context.Context, id int64) (res int64, err error)
- //mc: -key=listReadCountKey
- CacheListsReadCount(c context.Context, ids []int64) (res map[int64]int64, err error)
- //mc: -key=hotspotsKey -expire=d.mcHotspotExpire
- AddCacheHotspots(c context.Context, hots []*model.Hotspot) (err error)
- //mc: -key=hotspotsKey
- DelCacheHotspots(c context.Context) (err error)
- //mc: -key=hotspotsKey
- cacheHotspots(c context.Context) (res []*model.Hotspot, err error)
- //mc: -key=mcHotspotKey
- CacheHotspot(c context.Context, id int64) (res *model.Hotspot, err error)
- //mc: -key=mcHotspotKey -expire=d.mcHotspotExpire
- AddCacheHotspot(c context.Context, id int64, val *model.Hotspot) (err error)
- // 增加作者状态缓存
- //mc: -key=mcAuthorKey -expire=d.mcAuthorExpire
- AddCacheAuthor(c context.Context, mid int64, author *model.AuthorLimit) (err error)
- //mc: -key=mcAuthorKey
- CacheAuthor(c context.Context, mid int64) (res *model.AuthorLimit, err error)
- //mc: -key=mcAuthorKey
- DelCacheAuthor(c context.Context, mid int64) (err error)
- //mc: -key=slideArticlesKey
- CacheListArtsId(c context.Context, buvid string) (*model.ArticleViewList, error)
- //mc: -key=slideArticlesKey -expire=d.mcArticlesIDExpire
- AddCacheListArtsId(c context.Context, buvid string, val *model.ArticleViewList) error
- //mc: -key=slideArticlesKey
- DelCacheListArtsId(c context.Context, buvid string) error
- //mc: -key=AnniversaryKey -expire=60*60*24*30
- CacheAnniversary(c context.Context, mid int64) (*model.AnniversaryInfo, error)
- //mc: -key=mcTagKey
- CacheAidsByTag(c context.Context, tag int64) (*model.TagArts, error)
- //mc: -key=mcTagKey -expire=d.mcArticleTagExpire
- AddCacheAidsByTag(c context.Context, tag int64, val *model.TagArts) error
- //mc: -key=mcUpStatKey -expire=d.mcUpStatDailyExpire
- CacheUpStatDaily(c context.Context, mid int64) (*model.UpStat, error)
- //mc: -key=mcUpStatKey -expire=d.mcUpStatDailyExpire
- AddCacheUpStatDaily(c context.Context, mid int64, val *model.UpStat) error
- }
- */
- package dao
- import (
- "context"
- "fmt"
- "strconv"
- "go-common/app/interface/openplatform/article/model"
- "go-common/library/cache/memcache"
- "go-common/library/log"
- "go-common/library/stat/prom"
- )
- var _ _mc
- // CacheListArts 获取文集文章列表缓存
- func (d *Dao) CacheListArts(c context.Context, id int64) (res []*model.ListArtMeta, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := listArtsKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheListArts")
- log.Errorv(c, log.KV("CacheListArts", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = []*model.ListArtMeta{}
- err = conn.Scan(reply, &res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheListArts")
- log.Errorv(c, log.KV("CacheListArts", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheListArts 增加文集含有的文章列表缓存
- func (d *Dao) AddCacheListArts(c context.Context, id int64, val []*model.ListArtMeta) (err error) {
- if len(val) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := listArtsKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcListArtsExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheListArts")
- log.Errorv(c, log.KV("AddCacheListArts", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // ArticleListCache 获取文章所属文集
- func (d *Dao) ArticleListCache(c context.Context, id int64) (res int64, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := articleListKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:ArticleListCache")
- log.Errorv(c, log.KV("ArticleListCache", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- var v string
- err = conn.Scan(reply, &v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:ArticleListCache")
- log.Errorv(c, log.KV("ArticleListCache", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- r, err := strconv.ParseInt(v, 10, 64)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:ArticleListCache")
- log.Errorv(c, log.KV("ArticleListCache", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = int64(r)
- return
- }
- // SetArticlesListCache 增加文章所属文集缓存
- func (d *Dao) SetArticlesListCache(c context.Context, values map[int64]int64) (err error) {
- if len(values) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- for id, val := range values {
- key := articleListKey(id)
- bs := []byte(strconv.FormatInt(int64(val), 10))
- item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcArtListExpire, Flags: memcache.FlagRAW}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:SetArticlesListCache")
- log.Errorv(c, log.KV("SetArticlesListCache", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- }
- return
- }
- // CacheList get data from mc
- func (d *Dao) CacheList(c context.Context, id int64) (res *model.List, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := listKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheList")
- log.Errorv(c, log.KV("CacheList", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &model.List{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheList")
- log.Errorv(c, log.KV("CacheList", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheList Set data to mc
- func (d *Dao) AddCacheList(c context.Context, id int64, val *model.List) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := listKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcListExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheList")
- log.Errorv(c, log.KV("AddCacheList", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheLists get data from mc
- func (d *Dao) CacheLists(c context.Context, ids []int64) (res map[int64]*model.List, 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 := listKey(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:CacheLists")
- log.Errorv(c, log.KV("CacheLists", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
- return
- }
- for key, reply := range replies {
- var v *model.List
- v = &model.List{}
- err = conn.Scan(reply, v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheLists")
- log.Errorv(c, log.KV("CacheLists", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- if res == nil {
- res = make(map[int64]*model.List, len(keys))
- }
- res[keysMap[key]] = v
- }
- return
- }
- // AddCacheLists Set data to mc
- func (d *Dao) AddCacheLists(c context.Context, values map[int64]*model.List) (err error) {
- if len(values) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- for id, val := range values {
- key := listKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcListExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheLists")
- log.Errorv(c, log.KV("AddCacheLists", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- }
- return
- }
- // CacheListsArts get data from mc
- func (d *Dao) CacheListsArts(c context.Context, ids []int64) (res map[int64][]*model.ListArtMeta, 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 := listArtsKey(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:CacheListsArts")
- log.Errorv(c, log.KV("CacheListsArts", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
- return
- }
- for key, reply := range replies {
- var v []*model.ListArtMeta
- v = []*model.ListArtMeta{}
- err = conn.Scan(reply, &v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheListsArts")
- log.Errorv(c, log.KV("CacheListsArts", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- if res == nil {
- res = make(map[int64][]*model.ListArtMeta, len(keys))
- }
- res[keysMap[key]] = v
- }
- return
- }
- // AddCacheListsArts Set data to mc
- func (d *Dao) AddCacheListsArts(c context.Context, values map[int64][]*model.ListArtMeta) (err error) {
- if len(values) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- for id, val := range values {
- key := listArtsKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcListArtsExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheListsArts")
- log.Errorv(c, log.KV("AddCacheListsArts", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- }
- return
- }
- // CacheArtsListID get data from mc
- func (d *Dao) CacheArtsListID(c context.Context, ids []int64) (res map[int64]int64, 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 := articleListKey(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:CacheArtsListID")
- log.Errorv(c, log.KV("CacheArtsListID", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
- return
- }
- for key, reply := range replies {
- var v string
- err = conn.Scan(reply, &v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheArtsListID")
- log.Errorv(c, log.KV("CacheArtsListID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- r, err := strconv.ParseInt(v, 10, 64)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheArtsListID")
- log.Errorv(c, log.KV("CacheArtsListID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return res, err
- }
- if res == nil {
- res = make(map[int64]int64, len(keys))
- }
- res[keysMap[key]] = int64(r)
- }
- return
- }
- // AddCacheArtsListID Set data to mc
- func (d *Dao) AddCacheArtsListID(c context.Context, values map[int64]int64) (err error) {
- if len(values) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- for id, val := range values {
- key := articleListKey(id)
- bs := []byte(strconv.FormatInt(int64(val), 10))
- item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcArtListExpire, Flags: memcache.FlagRAW}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheArtsListID")
- log.Errorv(c, log.KV("AddCacheArtsListID", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- }
- return
- }
- // AddCacheUpLists Set data to mc
- func (d *Dao) AddCacheUpLists(c context.Context, id int64, val []int64) (err error) {
- if len(val) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := upListsKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcUpListsExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheUpLists")
- log.Errorv(c, log.KV("AddCacheUpLists", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheUpLists get data from mc
- func (d *Dao) CacheUpLists(c context.Context, id int64) (res []int64, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := upListsKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheUpLists")
- log.Errorv(c, log.KV("CacheUpLists", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = []int64{}
- err = conn.Scan(reply, &res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheUpLists")
- log.Errorv(c, log.KV("CacheUpLists", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheListReadCount Set data to mc
- func (d *Dao) AddCacheListReadCount(c context.Context, id int64, val int64) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := listReadCountKey(id)
- bs := []byte(strconv.FormatInt(int64(val), 10))
- item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcListReadExpire, Flags: memcache.FlagRAW}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheListReadCount")
- log.Errorv(c, log.KV("AddCacheListReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheListReadCount get data from mc
- func (d *Dao) CacheListReadCount(c context.Context, id int64) (res int64, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := listReadCountKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheListReadCount")
- log.Errorv(c, log.KV("CacheListReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- var v string
- err = conn.Scan(reply, &v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheListReadCount")
- log.Errorv(c, log.KV("CacheListReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- r, err := strconv.ParseInt(v, 10, 64)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheListReadCount")
- log.Errorv(c, log.KV("CacheListReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = int64(r)
- return
- }
- // CacheListsReadCount get data from mc
- func (d *Dao) CacheListsReadCount(c context.Context, ids []int64) (res map[int64]int64, 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 := listReadCountKey(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:CacheListsReadCount")
- log.Errorv(c, log.KV("CacheListsReadCount", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
- return
- }
- for key, reply := range replies {
- var v string
- err = conn.Scan(reply, &v)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheListsReadCount")
- log.Errorv(c, log.KV("CacheListsReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- r, err := strconv.ParseInt(v, 10, 64)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheListsReadCount")
- log.Errorv(c, log.KV("CacheListsReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return res, err
- }
- if res == nil {
- res = make(map[int64]int64, len(keys))
- }
- res[keysMap[key]] = int64(r)
- }
- return
- }
- // AddCacheHotspots Set data to mc
- func (d *Dao) AddCacheHotspots(c context.Context, val []*model.Hotspot) (err error) {
- if len(val) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := hotspotsKey()
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcHotspotExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheHotspots")
- log.Errorv(c, log.KV("AddCacheHotspots", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // DelCacheHotspots delete data from mc
- func (d *Dao) DelCacheHotspots(c context.Context) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := hotspotsKey()
- if err = conn.Delete(key); err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:DelCacheHotspots")
- log.Errorv(c, log.KV("DelCacheHotspots", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // cacheHotspots get data from mc
- func (d *Dao) cacheHotspots(c context.Context) (res []*model.Hotspot, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := hotspotsKey()
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:cacheHotspots")
- log.Errorv(c, log.KV("cacheHotspots", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = []*model.Hotspot{}
- err = conn.Scan(reply, &res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:cacheHotspots")
- log.Errorv(c, log.KV("cacheHotspots", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheHotspot get data from mc
- func (d *Dao) CacheHotspot(c context.Context, id int64) (res *model.Hotspot, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := mcHotspotKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheHotspot")
- log.Errorv(c, log.KV("CacheHotspot", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &model.Hotspot{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheHotspot")
- log.Errorv(c, log.KV("CacheHotspot", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheHotspot Set data to mc
- func (d *Dao) AddCacheHotspot(c context.Context, id int64, val *model.Hotspot) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := mcHotspotKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcHotspotExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheHotspot")
- log.Errorv(c, log.KV("AddCacheHotspot", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheAuthor 增加作者状态缓存
- func (d *Dao) AddCacheAuthor(c context.Context, id int64, val *model.AuthorLimit) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := mcAuthorKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcAuthorExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheAuthor")
- log.Errorv(c, log.KV("AddCacheAuthor", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheAuthor get data from mc
- func (d *Dao) CacheAuthor(c context.Context, id int64) (res *model.AuthorLimit, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := mcAuthorKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheAuthor")
- log.Errorv(c, log.KV("CacheAuthor", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &model.AuthorLimit{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheAuthor")
- log.Errorv(c, log.KV("CacheAuthor", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // DelCacheAuthor delete data from mc
- func (d *Dao) DelCacheAuthor(c context.Context, id int64) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := mcAuthorKey(id)
- if err = conn.Delete(key); err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:DelCacheAuthor")
- log.Errorv(c, log.KV("DelCacheAuthor", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheListArtsId get data from mc
- func (d *Dao) CacheListArtsId(c context.Context, id string) (res *model.ArticleViewList, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := slideArticlesKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheListArtsId")
- log.Errorv(c, log.KV("CacheListArtsId", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &model.ArticleViewList{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheListArtsId")
- log.Errorv(c, log.KV("CacheListArtsId", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheListArtsId Set data to mc
- func (d *Dao) AddCacheListArtsId(c context.Context, id string, val *model.ArticleViewList) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := slideArticlesKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcArticlesIDExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheListArtsId")
- log.Errorv(c, log.KV("AddCacheListArtsId", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // DelCacheListArtsId delete data from mc
- func (d *Dao) DelCacheListArtsId(c context.Context, id string) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := slideArticlesKey(id)
- if err = conn.Delete(key); err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:DelCacheListArtsId")
- log.Errorv(c, log.KV("DelCacheListArtsId", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheAnniversary get data from mc
- func (d *Dao) CacheAnniversary(c context.Context, id int64) (res *model.AnniversaryInfo, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := AnniversaryKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheAnniversary")
- log.Errorv(c, log.KV("CacheAnniversary", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &model.AnniversaryInfo{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheAnniversary")
- log.Errorv(c, log.KV("CacheAnniversary", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheAidsByTag get data from mc
- func (d *Dao) CacheAidsByTag(c context.Context, id int64) (res *model.TagArts, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := mcTagKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheAidsByTag")
- log.Errorv(c, log.KV("CacheAidsByTag", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &model.TagArts{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheAidsByTag")
- log.Errorv(c, log.KV("CacheAidsByTag", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheAidsByTag Set data to mc
- func (d *Dao) AddCacheAidsByTag(c context.Context, id int64, val *model.TagArts) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := mcTagKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcArticleTagExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheAidsByTag")
- log.Errorv(c, log.KV("AddCacheAidsByTag", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // CacheUpStatDaily get data from mc
- func (d *Dao) CacheUpStatDaily(c context.Context, id int64) (res *model.UpStat, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := mcUpStatKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheUpStatDaily")
- log.Errorv(c, log.KV("CacheUpStatDaily", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &model.UpStat{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheUpStatDaily")
- log.Errorv(c, log.KV("CacheUpStatDaily", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- // AddCacheUpStatDaily Set data to mc
- func (d *Dao) AddCacheUpStatDaily(c context.Context, id int64, val *model.UpStat) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := mcUpStatKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: d.mcUpStatDailyExpire, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheUpStatDaily")
- log.Errorv(c, log.KV("AddCacheUpStatDaily", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
|