mc.cache.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
  2. /*
  3. Package dao is a generated mc cache package.
  4. It is generated from:
  5. type _mc interface {
  6. // 获取文集文章列表缓存
  7. //mc: -key=listArtsKey
  8. CacheListArts(c context.Context, id int64) (res []*model.ListArtMeta, err error)
  9. // 增加文集含有的文章列表缓存
  10. //mc: -key=listArtsKey -expire=d.mcListArtsExpire
  11. AddCacheListArts(c context.Context, id int64, arts []*model.ListArtMeta) (err error)
  12. // 获取文章所属文集
  13. //mc: -key=articleListKey -type=get
  14. ArticleListCache(c context.Context, id int64) (res int64, err error)
  15. // 增加文章所属文集缓存
  16. //mc: -key=articleListKey -expire=d.mcArtListExpire
  17. SetArticlesListCache(c context.Context, arts map[int64]int64) (err error)
  18. //mc: -key=listKey
  19. CacheList(c context.Context, id int64) (res *model.List, err error)
  20. //mc: -key=listKey -expire=d.mcListExpire
  21. AddCacheList(c context.Context, id int64, list *model.List) (err error)
  22. //mc: -key=listKey
  23. CacheLists(c context.Context, ids []int64) (res map[int64]*model.List, err error)
  24. //mc: -key=listKey -expire=d.mcListExpire
  25. AddCacheLists(c context.Context, lists map[int64]*model.List) (err error)
  26. //mc: -key=listArtsKey
  27. CacheListsArts(c context.Context, ids []int64) (res map[int64][]*model.ListArtMeta, err error)
  28. //mc: -key=listArtsKey -expire=d.mcListArtsExpire
  29. AddCacheListsArts(c context.Context, arts map[int64][]*model.ListArtMeta) (err error)
  30. //mc: -key=articleListKey
  31. CacheArtsListID(c context.Context, ids []int64) (res map[int64]int64, err error)
  32. //mc: -key=articleListKey -expire=d.mcArtListExpire
  33. AddCacheArtsListID(c context.Context, arts map[int64]int64) (err error)
  34. //mc: -key=upListsKey -expire=d.mcUpListsExpire
  35. AddCacheUpLists(c context.Context, mid int64, lists []int64) (err error)
  36. //mc: -key=upListsKey
  37. CacheUpLists(c context.Context, id int64) (res []int64, err error)
  38. //mc: -key=listReadCountKey -expire=d.mcListReadExpire
  39. AddCacheListReadCount(c context.Context, id int64, read int64) (err error)
  40. //mc: -key=listReadCountKey
  41. CacheListReadCount(c context.Context, id int64) (res int64, err error)
  42. //mc: -key=listReadCountKey
  43. CacheListsReadCount(c context.Context, ids []int64) (res map[int64]int64, err error)
  44. //mc: -key=hotspotsKey -expire=d.mcHotspotExpire
  45. AddCacheHotspots(c context.Context, hots []*model.Hotspot) (err error)
  46. //mc: -key=hotspotsKey
  47. DelCacheHotspots(c context.Context) (err error)
  48. //mc: -key=hotspotsKey
  49. cacheHotspots(c context.Context) (res []*model.Hotspot, err error)
  50. //mc: -key=mcHotspotKey
  51. CacheHotspot(c context.Context, id int64) (res *model.Hotspot, err error)
  52. //mc: -key=mcHotspotKey -expire=d.mcHotspotExpire
  53. AddCacheHotspot(c context.Context, id int64, val *model.Hotspot) (err error)
  54. // 增加作者状态缓存
  55. //mc: -key=mcAuthorKey -expire=d.mcAuthorExpire
  56. AddCacheAuthor(c context.Context, mid int64, author *model.AuthorLimit) (err error)
  57. //mc: -key=mcAuthorKey
  58. CacheAuthor(c context.Context, mid int64) (res *model.AuthorLimit, err error)
  59. //mc: -key=mcAuthorKey
  60. DelCacheAuthor(c context.Context, mid int64) (err error)
  61. //mc: -key=slideArticlesKey
  62. CacheListArtsId(c context.Context, buvid string) (*model.ArticleViewList, error)
  63. //mc: -key=slideArticlesKey -expire=d.mcArticlesIDExpire
  64. AddCacheListArtsId(c context.Context, buvid string, val *model.ArticleViewList) error
  65. //mc: -key=slideArticlesKey
  66. DelCacheListArtsId(c context.Context, buvid string) error
  67. //mc: -key=AnniversaryKey -expire=60*60*24*30
  68. CacheAnniversary(c context.Context, mid int64) (*model.AnniversaryInfo, error)
  69. //mc: -key=mcTagKey
  70. CacheAidsByTag(c context.Context, tag int64) (*model.TagArts, error)
  71. //mc: -key=mcTagKey -expire=d.mcArticleTagExpire
  72. AddCacheAidsByTag(c context.Context, tag int64, val *model.TagArts) error
  73. //mc: -key=mcUpStatKey -expire=d.mcUpStatDailyExpire
  74. CacheUpStatDaily(c context.Context, mid int64) (*model.UpStat, error)
  75. //mc: -key=mcUpStatKey -expire=d.mcUpStatDailyExpire
  76. AddCacheUpStatDaily(c context.Context, mid int64, val *model.UpStat) error
  77. }
  78. */
  79. package dao
  80. import (
  81. "context"
  82. "fmt"
  83. "strconv"
  84. "go-common/app/interface/openplatform/article/model"
  85. "go-common/library/cache/memcache"
  86. "go-common/library/log"
  87. "go-common/library/stat/prom"
  88. )
  89. var _ _mc
  90. // CacheListArts 获取文集文章列表缓存
  91. func (d *Dao) CacheListArts(c context.Context, id int64) (res []*model.ListArtMeta, err error) {
  92. conn := d.mc.Get(c)
  93. defer conn.Close()
  94. key := listArtsKey(id)
  95. reply, err := conn.Get(key)
  96. if err != nil {
  97. if err == memcache.ErrNotFound {
  98. err = nil
  99. return
  100. }
  101. prom.BusinessErrCount.Incr("mc:CacheListArts")
  102. log.Errorv(c, log.KV("CacheListArts", fmt.Sprintf("%+v", err)), log.KV("key", key))
  103. return
  104. }
  105. res = []*model.ListArtMeta{}
  106. err = conn.Scan(reply, &res)
  107. if err != nil {
  108. prom.BusinessErrCount.Incr("mc:CacheListArts")
  109. log.Errorv(c, log.KV("CacheListArts", fmt.Sprintf("%+v", err)), log.KV("key", key))
  110. return
  111. }
  112. return
  113. }
  114. // AddCacheListArts 增加文集含有的文章列表缓存
  115. func (d *Dao) AddCacheListArts(c context.Context, id int64, val []*model.ListArtMeta) (err error) {
  116. if len(val) == 0 {
  117. return
  118. }
  119. conn := d.mc.Get(c)
  120. defer conn.Close()
  121. key := listArtsKey(id)
  122. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcListArtsExpire, Flags: memcache.FlagJSON}
  123. if err = conn.Set(item); err != nil {
  124. prom.BusinessErrCount.Incr("mc:AddCacheListArts")
  125. log.Errorv(c, log.KV("AddCacheListArts", fmt.Sprintf("%+v", err)), log.KV("key", key))
  126. return
  127. }
  128. return
  129. }
  130. // ArticleListCache 获取文章所属文集
  131. func (d *Dao) ArticleListCache(c context.Context, id int64) (res int64, err error) {
  132. conn := d.mc.Get(c)
  133. defer conn.Close()
  134. key := articleListKey(id)
  135. reply, err := conn.Get(key)
  136. if err != nil {
  137. if err == memcache.ErrNotFound {
  138. err = nil
  139. return
  140. }
  141. prom.BusinessErrCount.Incr("mc:ArticleListCache")
  142. log.Errorv(c, log.KV("ArticleListCache", fmt.Sprintf("%+v", err)), log.KV("key", key))
  143. return
  144. }
  145. var v string
  146. err = conn.Scan(reply, &v)
  147. if err != nil {
  148. prom.BusinessErrCount.Incr("mc:ArticleListCache")
  149. log.Errorv(c, log.KV("ArticleListCache", fmt.Sprintf("%+v", err)), log.KV("key", key))
  150. return
  151. }
  152. r, err := strconv.ParseInt(v, 10, 64)
  153. if err != nil {
  154. prom.BusinessErrCount.Incr("mc:ArticleListCache")
  155. log.Errorv(c, log.KV("ArticleListCache", fmt.Sprintf("%+v", err)), log.KV("key", key))
  156. return
  157. }
  158. res = int64(r)
  159. return
  160. }
  161. // SetArticlesListCache 增加文章所属文集缓存
  162. func (d *Dao) SetArticlesListCache(c context.Context, values map[int64]int64) (err error) {
  163. if len(values) == 0 {
  164. return
  165. }
  166. conn := d.mc.Get(c)
  167. defer conn.Close()
  168. for id, val := range values {
  169. key := articleListKey(id)
  170. bs := []byte(strconv.FormatInt(int64(val), 10))
  171. item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcArtListExpire, Flags: memcache.FlagRAW}
  172. if err = conn.Set(item); err != nil {
  173. prom.BusinessErrCount.Incr("mc:SetArticlesListCache")
  174. log.Errorv(c, log.KV("SetArticlesListCache", fmt.Sprintf("%+v", err)), log.KV("key", key))
  175. return
  176. }
  177. }
  178. return
  179. }
  180. // CacheList get data from mc
  181. func (d *Dao) CacheList(c context.Context, id int64) (res *model.List, err error) {
  182. conn := d.mc.Get(c)
  183. defer conn.Close()
  184. key := listKey(id)
  185. reply, err := conn.Get(key)
  186. if err != nil {
  187. if err == memcache.ErrNotFound {
  188. err = nil
  189. return
  190. }
  191. prom.BusinessErrCount.Incr("mc:CacheList")
  192. log.Errorv(c, log.KV("CacheList", fmt.Sprintf("%+v", err)), log.KV("key", key))
  193. return
  194. }
  195. res = &model.List{}
  196. err = conn.Scan(reply, res)
  197. if err != nil {
  198. prom.BusinessErrCount.Incr("mc:CacheList")
  199. log.Errorv(c, log.KV("CacheList", fmt.Sprintf("%+v", err)), log.KV("key", key))
  200. return
  201. }
  202. return
  203. }
  204. // AddCacheList Set data to mc
  205. func (d *Dao) AddCacheList(c context.Context, id int64, val *model.List) (err error) {
  206. if val == nil {
  207. return
  208. }
  209. conn := d.mc.Get(c)
  210. defer conn.Close()
  211. key := listKey(id)
  212. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcListExpire, Flags: memcache.FlagJSON}
  213. if err = conn.Set(item); err != nil {
  214. prom.BusinessErrCount.Incr("mc:AddCacheList")
  215. log.Errorv(c, log.KV("AddCacheList", fmt.Sprintf("%+v", err)), log.KV("key", key))
  216. return
  217. }
  218. return
  219. }
  220. // CacheLists get data from mc
  221. func (d *Dao) CacheLists(c context.Context, ids []int64) (res map[int64]*model.List, err error) {
  222. l := len(ids)
  223. if l == 0 {
  224. return
  225. }
  226. keysMap := make(map[string]int64, l)
  227. keys := make([]string, 0, l)
  228. for _, id := range ids {
  229. key := listKey(id)
  230. keysMap[key] = id
  231. keys = append(keys, key)
  232. }
  233. conn := d.mc.Get(c)
  234. defer conn.Close()
  235. replies, err := conn.GetMulti(keys)
  236. if err != nil {
  237. prom.BusinessErrCount.Incr("mc:CacheLists")
  238. log.Errorv(c, log.KV("CacheLists", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
  239. return
  240. }
  241. for key, reply := range replies {
  242. var v *model.List
  243. v = &model.List{}
  244. err = conn.Scan(reply, v)
  245. if err != nil {
  246. prom.BusinessErrCount.Incr("mc:CacheLists")
  247. log.Errorv(c, log.KV("CacheLists", fmt.Sprintf("%+v", err)), log.KV("key", key))
  248. return
  249. }
  250. if res == nil {
  251. res = make(map[int64]*model.List, len(keys))
  252. }
  253. res[keysMap[key]] = v
  254. }
  255. return
  256. }
  257. // AddCacheLists Set data to mc
  258. func (d *Dao) AddCacheLists(c context.Context, values map[int64]*model.List) (err error) {
  259. if len(values) == 0 {
  260. return
  261. }
  262. conn := d.mc.Get(c)
  263. defer conn.Close()
  264. for id, val := range values {
  265. key := listKey(id)
  266. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcListExpire, Flags: memcache.FlagJSON}
  267. if err = conn.Set(item); err != nil {
  268. prom.BusinessErrCount.Incr("mc:AddCacheLists")
  269. log.Errorv(c, log.KV("AddCacheLists", fmt.Sprintf("%+v", err)), log.KV("key", key))
  270. return
  271. }
  272. }
  273. return
  274. }
  275. // CacheListsArts get data from mc
  276. func (d *Dao) CacheListsArts(c context.Context, ids []int64) (res map[int64][]*model.ListArtMeta, err error) {
  277. l := len(ids)
  278. if l == 0 {
  279. return
  280. }
  281. keysMap := make(map[string]int64, l)
  282. keys := make([]string, 0, l)
  283. for _, id := range ids {
  284. key := listArtsKey(id)
  285. keysMap[key] = id
  286. keys = append(keys, key)
  287. }
  288. conn := d.mc.Get(c)
  289. defer conn.Close()
  290. replies, err := conn.GetMulti(keys)
  291. if err != nil {
  292. prom.BusinessErrCount.Incr("mc:CacheListsArts")
  293. log.Errorv(c, log.KV("CacheListsArts", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
  294. return
  295. }
  296. for key, reply := range replies {
  297. var v []*model.ListArtMeta
  298. v = []*model.ListArtMeta{}
  299. err = conn.Scan(reply, &v)
  300. if err != nil {
  301. prom.BusinessErrCount.Incr("mc:CacheListsArts")
  302. log.Errorv(c, log.KV("CacheListsArts", fmt.Sprintf("%+v", err)), log.KV("key", key))
  303. return
  304. }
  305. if res == nil {
  306. res = make(map[int64][]*model.ListArtMeta, len(keys))
  307. }
  308. res[keysMap[key]] = v
  309. }
  310. return
  311. }
  312. // AddCacheListsArts Set data to mc
  313. func (d *Dao) AddCacheListsArts(c context.Context, values map[int64][]*model.ListArtMeta) (err error) {
  314. if len(values) == 0 {
  315. return
  316. }
  317. conn := d.mc.Get(c)
  318. defer conn.Close()
  319. for id, val := range values {
  320. key := listArtsKey(id)
  321. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcListArtsExpire, Flags: memcache.FlagJSON}
  322. if err = conn.Set(item); err != nil {
  323. prom.BusinessErrCount.Incr("mc:AddCacheListsArts")
  324. log.Errorv(c, log.KV("AddCacheListsArts", fmt.Sprintf("%+v", err)), log.KV("key", key))
  325. return
  326. }
  327. }
  328. return
  329. }
  330. // CacheArtsListID get data from mc
  331. func (d *Dao) CacheArtsListID(c context.Context, ids []int64) (res map[int64]int64, err error) {
  332. l := len(ids)
  333. if l == 0 {
  334. return
  335. }
  336. keysMap := make(map[string]int64, l)
  337. keys := make([]string, 0, l)
  338. for _, id := range ids {
  339. key := articleListKey(id)
  340. keysMap[key] = id
  341. keys = append(keys, key)
  342. }
  343. conn := d.mc.Get(c)
  344. defer conn.Close()
  345. replies, err := conn.GetMulti(keys)
  346. if err != nil {
  347. prom.BusinessErrCount.Incr("mc:CacheArtsListID")
  348. log.Errorv(c, log.KV("CacheArtsListID", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
  349. return
  350. }
  351. for key, reply := range replies {
  352. var v string
  353. err = conn.Scan(reply, &v)
  354. if err != nil {
  355. prom.BusinessErrCount.Incr("mc:CacheArtsListID")
  356. log.Errorv(c, log.KV("CacheArtsListID", fmt.Sprintf("%+v", err)), log.KV("key", key))
  357. return
  358. }
  359. r, err := strconv.ParseInt(v, 10, 64)
  360. if err != nil {
  361. prom.BusinessErrCount.Incr("mc:CacheArtsListID")
  362. log.Errorv(c, log.KV("CacheArtsListID", fmt.Sprintf("%+v", err)), log.KV("key", key))
  363. return res, err
  364. }
  365. if res == nil {
  366. res = make(map[int64]int64, len(keys))
  367. }
  368. res[keysMap[key]] = int64(r)
  369. }
  370. return
  371. }
  372. // AddCacheArtsListID Set data to mc
  373. func (d *Dao) AddCacheArtsListID(c context.Context, values map[int64]int64) (err error) {
  374. if len(values) == 0 {
  375. return
  376. }
  377. conn := d.mc.Get(c)
  378. defer conn.Close()
  379. for id, val := range values {
  380. key := articleListKey(id)
  381. bs := []byte(strconv.FormatInt(int64(val), 10))
  382. item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcArtListExpire, Flags: memcache.FlagRAW}
  383. if err = conn.Set(item); err != nil {
  384. prom.BusinessErrCount.Incr("mc:AddCacheArtsListID")
  385. log.Errorv(c, log.KV("AddCacheArtsListID", fmt.Sprintf("%+v", err)), log.KV("key", key))
  386. return
  387. }
  388. }
  389. return
  390. }
  391. // AddCacheUpLists Set data to mc
  392. func (d *Dao) AddCacheUpLists(c context.Context, id int64, val []int64) (err error) {
  393. if len(val) == 0 {
  394. return
  395. }
  396. conn := d.mc.Get(c)
  397. defer conn.Close()
  398. key := upListsKey(id)
  399. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcUpListsExpire, Flags: memcache.FlagJSON}
  400. if err = conn.Set(item); err != nil {
  401. prom.BusinessErrCount.Incr("mc:AddCacheUpLists")
  402. log.Errorv(c, log.KV("AddCacheUpLists", fmt.Sprintf("%+v", err)), log.KV("key", key))
  403. return
  404. }
  405. return
  406. }
  407. // CacheUpLists get data from mc
  408. func (d *Dao) CacheUpLists(c context.Context, id int64) (res []int64, err error) {
  409. conn := d.mc.Get(c)
  410. defer conn.Close()
  411. key := upListsKey(id)
  412. reply, err := conn.Get(key)
  413. if err != nil {
  414. if err == memcache.ErrNotFound {
  415. err = nil
  416. return
  417. }
  418. prom.BusinessErrCount.Incr("mc:CacheUpLists")
  419. log.Errorv(c, log.KV("CacheUpLists", fmt.Sprintf("%+v", err)), log.KV("key", key))
  420. return
  421. }
  422. res = []int64{}
  423. err = conn.Scan(reply, &res)
  424. if err != nil {
  425. prom.BusinessErrCount.Incr("mc:CacheUpLists")
  426. log.Errorv(c, log.KV("CacheUpLists", fmt.Sprintf("%+v", err)), log.KV("key", key))
  427. return
  428. }
  429. return
  430. }
  431. // AddCacheListReadCount Set data to mc
  432. func (d *Dao) AddCacheListReadCount(c context.Context, id int64, val int64) (err error) {
  433. conn := d.mc.Get(c)
  434. defer conn.Close()
  435. key := listReadCountKey(id)
  436. bs := []byte(strconv.FormatInt(int64(val), 10))
  437. item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcListReadExpire, Flags: memcache.FlagRAW}
  438. if err = conn.Set(item); err != nil {
  439. prom.BusinessErrCount.Incr("mc:AddCacheListReadCount")
  440. log.Errorv(c, log.KV("AddCacheListReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
  441. return
  442. }
  443. return
  444. }
  445. // CacheListReadCount get data from mc
  446. func (d *Dao) CacheListReadCount(c context.Context, id int64) (res int64, err error) {
  447. conn := d.mc.Get(c)
  448. defer conn.Close()
  449. key := listReadCountKey(id)
  450. reply, err := conn.Get(key)
  451. if err != nil {
  452. if err == memcache.ErrNotFound {
  453. err = nil
  454. return
  455. }
  456. prom.BusinessErrCount.Incr("mc:CacheListReadCount")
  457. log.Errorv(c, log.KV("CacheListReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
  458. return
  459. }
  460. var v string
  461. err = conn.Scan(reply, &v)
  462. if err != nil {
  463. prom.BusinessErrCount.Incr("mc:CacheListReadCount")
  464. log.Errorv(c, log.KV("CacheListReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
  465. return
  466. }
  467. r, err := strconv.ParseInt(v, 10, 64)
  468. if err != nil {
  469. prom.BusinessErrCount.Incr("mc:CacheListReadCount")
  470. log.Errorv(c, log.KV("CacheListReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
  471. return
  472. }
  473. res = int64(r)
  474. return
  475. }
  476. // CacheListsReadCount get data from mc
  477. func (d *Dao) CacheListsReadCount(c context.Context, ids []int64) (res map[int64]int64, err error) {
  478. l := len(ids)
  479. if l == 0 {
  480. return
  481. }
  482. keysMap := make(map[string]int64, l)
  483. keys := make([]string, 0, l)
  484. for _, id := range ids {
  485. key := listReadCountKey(id)
  486. keysMap[key] = id
  487. keys = append(keys, key)
  488. }
  489. conn := d.mc.Get(c)
  490. defer conn.Close()
  491. replies, err := conn.GetMulti(keys)
  492. if err != nil {
  493. prom.BusinessErrCount.Incr("mc:CacheListsReadCount")
  494. log.Errorv(c, log.KV("CacheListsReadCount", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
  495. return
  496. }
  497. for key, reply := range replies {
  498. var v string
  499. err = conn.Scan(reply, &v)
  500. if err != nil {
  501. prom.BusinessErrCount.Incr("mc:CacheListsReadCount")
  502. log.Errorv(c, log.KV("CacheListsReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
  503. return
  504. }
  505. r, err := strconv.ParseInt(v, 10, 64)
  506. if err != nil {
  507. prom.BusinessErrCount.Incr("mc:CacheListsReadCount")
  508. log.Errorv(c, log.KV("CacheListsReadCount", fmt.Sprintf("%+v", err)), log.KV("key", key))
  509. return res, err
  510. }
  511. if res == nil {
  512. res = make(map[int64]int64, len(keys))
  513. }
  514. res[keysMap[key]] = int64(r)
  515. }
  516. return
  517. }
  518. // AddCacheHotspots Set data to mc
  519. func (d *Dao) AddCacheHotspots(c context.Context, val []*model.Hotspot) (err error) {
  520. if len(val) == 0 {
  521. return
  522. }
  523. conn := d.mc.Get(c)
  524. defer conn.Close()
  525. key := hotspotsKey()
  526. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcHotspotExpire, Flags: memcache.FlagJSON}
  527. if err = conn.Set(item); err != nil {
  528. prom.BusinessErrCount.Incr("mc:AddCacheHotspots")
  529. log.Errorv(c, log.KV("AddCacheHotspots", fmt.Sprintf("%+v", err)), log.KV("key", key))
  530. return
  531. }
  532. return
  533. }
  534. // DelCacheHotspots delete data from mc
  535. func (d *Dao) DelCacheHotspots(c context.Context) (err error) {
  536. conn := d.mc.Get(c)
  537. defer conn.Close()
  538. key := hotspotsKey()
  539. if err = conn.Delete(key); err != nil {
  540. if err == memcache.ErrNotFound {
  541. err = nil
  542. return
  543. }
  544. prom.BusinessErrCount.Incr("mc:DelCacheHotspots")
  545. log.Errorv(c, log.KV("DelCacheHotspots", fmt.Sprintf("%+v", err)), log.KV("key", key))
  546. return
  547. }
  548. return
  549. }
  550. // cacheHotspots get data from mc
  551. func (d *Dao) cacheHotspots(c context.Context) (res []*model.Hotspot, err error) {
  552. conn := d.mc.Get(c)
  553. defer conn.Close()
  554. key := hotspotsKey()
  555. reply, err := conn.Get(key)
  556. if err != nil {
  557. if err == memcache.ErrNotFound {
  558. err = nil
  559. return
  560. }
  561. prom.BusinessErrCount.Incr("mc:cacheHotspots")
  562. log.Errorv(c, log.KV("cacheHotspots", fmt.Sprintf("%+v", err)), log.KV("key", key))
  563. return
  564. }
  565. res = []*model.Hotspot{}
  566. err = conn.Scan(reply, &res)
  567. if err != nil {
  568. prom.BusinessErrCount.Incr("mc:cacheHotspots")
  569. log.Errorv(c, log.KV("cacheHotspots", fmt.Sprintf("%+v", err)), log.KV("key", key))
  570. return
  571. }
  572. return
  573. }
  574. // CacheHotspot get data from mc
  575. func (d *Dao) CacheHotspot(c context.Context, id int64) (res *model.Hotspot, err error) {
  576. conn := d.mc.Get(c)
  577. defer conn.Close()
  578. key := mcHotspotKey(id)
  579. reply, err := conn.Get(key)
  580. if err != nil {
  581. if err == memcache.ErrNotFound {
  582. err = nil
  583. return
  584. }
  585. prom.BusinessErrCount.Incr("mc:CacheHotspot")
  586. log.Errorv(c, log.KV("CacheHotspot", fmt.Sprintf("%+v", err)), log.KV("key", key))
  587. return
  588. }
  589. res = &model.Hotspot{}
  590. err = conn.Scan(reply, res)
  591. if err != nil {
  592. prom.BusinessErrCount.Incr("mc:CacheHotspot")
  593. log.Errorv(c, log.KV("CacheHotspot", fmt.Sprintf("%+v", err)), log.KV("key", key))
  594. return
  595. }
  596. return
  597. }
  598. // AddCacheHotspot Set data to mc
  599. func (d *Dao) AddCacheHotspot(c context.Context, id int64, val *model.Hotspot) (err error) {
  600. if val == nil {
  601. return
  602. }
  603. conn := d.mc.Get(c)
  604. defer conn.Close()
  605. key := mcHotspotKey(id)
  606. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcHotspotExpire, Flags: memcache.FlagJSON}
  607. if err = conn.Set(item); err != nil {
  608. prom.BusinessErrCount.Incr("mc:AddCacheHotspot")
  609. log.Errorv(c, log.KV("AddCacheHotspot", fmt.Sprintf("%+v", err)), log.KV("key", key))
  610. return
  611. }
  612. return
  613. }
  614. // AddCacheAuthor 增加作者状态缓存
  615. func (d *Dao) AddCacheAuthor(c context.Context, id int64, val *model.AuthorLimit) (err error) {
  616. if val == nil {
  617. return
  618. }
  619. conn := d.mc.Get(c)
  620. defer conn.Close()
  621. key := mcAuthorKey(id)
  622. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcAuthorExpire, Flags: memcache.FlagJSON}
  623. if err = conn.Set(item); err != nil {
  624. prom.BusinessErrCount.Incr("mc:AddCacheAuthor")
  625. log.Errorv(c, log.KV("AddCacheAuthor", fmt.Sprintf("%+v", err)), log.KV("key", key))
  626. return
  627. }
  628. return
  629. }
  630. // CacheAuthor get data from mc
  631. func (d *Dao) CacheAuthor(c context.Context, id int64) (res *model.AuthorLimit, err error) {
  632. conn := d.mc.Get(c)
  633. defer conn.Close()
  634. key := mcAuthorKey(id)
  635. reply, err := conn.Get(key)
  636. if err != nil {
  637. if err == memcache.ErrNotFound {
  638. err = nil
  639. return
  640. }
  641. prom.BusinessErrCount.Incr("mc:CacheAuthor")
  642. log.Errorv(c, log.KV("CacheAuthor", fmt.Sprintf("%+v", err)), log.KV("key", key))
  643. return
  644. }
  645. res = &model.AuthorLimit{}
  646. err = conn.Scan(reply, res)
  647. if err != nil {
  648. prom.BusinessErrCount.Incr("mc:CacheAuthor")
  649. log.Errorv(c, log.KV("CacheAuthor", fmt.Sprintf("%+v", err)), log.KV("key", key))
  650. return
  651. }
  652. return
  653. }
  654. // DelCacheAuthor delete data from mc
  655. func (d *Dao) DelCacheAuthor(c context.Context, id int64) (err error) {
  656. conn := d.mc.Get(c)
  657. defer conn.Close()
  658. key := mcAuthorKey(id)
  659. if err = conn.Delete(key); err != nil {
  660. if err == memcache.ErrNotFound {
  661. err = nil
  662. return
  663. }
  664. prom.BusinessErrCount.Incr("mc:DelCacheAuthor")
  665. log.Errorv(c, log.KV("DelCacheAuthor", fmt.Sprintf("%+v", err)), log.KV("key", key))
  666. return
  667. }
  668. return
  669. }
  670. // CacheListArtsId get data from mc
  671. func (d *Dao) CacheListArtsId(c context.Context, id string) (res *model.ArticleViewList, err error) {
  672. conn := d.mc.Get(c)
  673. defer conn.Close()
  674. key := slideArticlesKey(id)
  675. reply, err := conn.Get(key)
  676. if err != nil {
  677. if err == memcache.ErrNotFound {
  678. err = nil
  679. return
  680. }
  681. prom.BusinessErrCount.Incr("mc:CacheListArtsId")
  682. log.Errorv(c, log.KV("CacheListArtsId", fmt.Sprintf("%+v", err)), log.KV("key", key))
  683. return
  684. }
  685. res = &model.ArticleViewList{}
  686. err = conn.Scan(reply, res)
  687. if err != nil {
  688. prom.BusinessErrCount.Incr("mc:CacheListArtsId")
  689. log.Errorv(c, log.KV("CacheListArtsId", fmt.Sprintf("%+v", err)), log.KV("key", key))
  690. return
  691. }
  692. return
  693. }
  694. // AddCacheListArtsId Set data to mc
  695. func (d *Dao) AddCacheListArtsId(c context.Context, id string, val *model.ArticleViewList) (err error) {
  696. if val == nil {
  697. return
  698. }
  699. conn := d.mc.Get(c)
  700. defer conn.Close()
  701. key := slideArticlesKey(id)
  702. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcArticlesIDExpire, Flags: memcache.FlagJSON}
  703. if err = conn.Set(item); err != nil {
  704. prom.BusinessErrCount.Incr("mc:AddCacheListArtsId")
  705. log.Errorv(c, log.KV("AddCacheListArtsId", fmt.Sprintf("%+v", err)), log.KV("key", key))
  706. return
  707. }
  708. return
  709. }
  710. // DelCacheListArtsId delete data from mc
  711. func (d *Dao) DelCacheListArtsId(c context.Context, id string) (err error) {
  712. conn := d.mc.Get(c)
  713. defer conn.Close()
  714. key := slideArticlesKey(id)
  715. if err = conn.Delete(key); err != nil {
  716. if err == memcache.ErrNotFound {
  717. err = nil
  718. return
  719. }
  720. prom.BusinessErrCount.Incr("mc:DelCacheListArtsId")
  721. log.Errorv(c, log.KV("DelCacheListArtsId", fmt.Sprintf("%+v", err)), log.KV("key", key))
  722. return
  723. }
  724. return
  725. }
  726. // CacheAnniversary get data from mc
  727. func (d *Dao) CacheAnniversary(c context.Context, id int64) (res *model.AnniversaryInfo, err error) {
  728. conn := d.mc.Get(c)
  729. defer conn.Close()
  730. key := AnniversaryKey(id)
  731. reply, err := conn.Get(key)
  732. if err != nil {
  733. if err == memcache.ErrNotFound {
  734. err = nil
  735. return
  736. }
  737. prom.BusinessErrCount.Incr("mc:CacheAnniversary")
  738. log.Errorv(c, log.KV("CacheAnniversary", fmt.Sprintf("%+v", err)), log.KV("key", key))
  739. return
  740. }
  741. res = &model.AnniversaryInfo{}
  742. err = conn.Scan(reply, res)
  743. if err != nil {
  744. prom.BusinessErrCount.Incr("mc:CacheAnniversary")
  745. log.Errorv(c, log.KV("CacheAnniversary", fmt.Sprintf("%+v", err)), log.KV("key", key))
  746. return
  747. }
  748. return
  749. }
  750. // CacheAidsByTag get data from mc
  751. func (d *Dao) CacheAidsByTag(c context.Context, id int64) (res *model.TagArts, err error) {
  752. conn := d.mc.Get(c)
  753. defer conn.Close()
  754. key := mcTagKey(id)
  755. reply, err := conn.Get(key)
  756. if err != nil {
  757. if err == memcache.ErrNotFound {
  758. err = nil
  759. return
  760. }
  761. prom.BusinessErrCount.Incr("mc:CacheAidsByTag")
  762. log.Errorv(c, log.KV("CacheAidsByTag", fmt.Sprintf("%+v", err)), log.KV("key", key))
  763. return
  764. }
  765. res = &model.TagArts{}
  766. err = conn.Scan(reply, res)
  767. if err != nil {
  768. prom.BusinessErrCount.Incr("mc:CacheAidsByTag")
  769. log.Errorv(c, log.KV("CacheAidsByTag", fmt.Sprintf("%+v", err)), log.KV("key", key))
  770. return
  771. }
  772. return
  773. }
  774. // AddCacheAidsByTag Set data to mc
  775. func (d *Dao) AddCacheAidsByTag(c context.Context, id int64, val *model.TagArts) (err error) {
  776. if val == nil {
  777. return
  778. }
  779. conn := d.mc.Get(c)
  780. defer conn.Close()
  781. key := mcTagKey(id)
  782. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcArticleTagExpire, Flags: memcache.FlagJSON}
  783. if err = conn.Set(item); err != nil {
  784. prom.BusinessErrCount.Incr("mc:AddCacheAidsByTag")
  785. log.Errorv(c, log.KV("AddCacheAidsByTag", fmt.Sprintf("%+v", err)), log.KV("key", key))
  786. return
  787. }
  788. return
  789. }
  790. // CacheUpStatDaily get data from mc
  791. func (d *Dao) CacheUpStatDaily(c context.Context, id int64) (res *model.UpStat, err error) {
  792. conn := d.mc.Get(c)
  793. defer conn.Close()
  794. key := mcUpStatKey(id)
  795. reply, err := conn.Get(key)
  796. if err != nil {
  797. if err == memcache.ErrNotFound {
  798. err = nil
  799. return
  800. }
  801. prom.BusinessErrCount.Incr("mc:CacheUpStatDaily")
  802. log.Errorv(c, log.KV("CacheUpStatDaily", fmt.Sprintf("%+v", err)), log.KV("key", key))
  803. return
  804. }
  805. res = &model.UpStat{}
  806. err = conn.Scan(reply, res)
  807. if err != nil {
  808. prom.BusinessErrCount.Incr("mc:CacheUpStatDaily")
  809. log.Errorv(c, log.KV("CacheUpStatDaily", fmt.Sprintf("%+v", err)), log.KV("key", key))
  810. return
  811. }
  812. return
  813. }
  814. // AddCacheUpStatDaily Set data to mc
  815. func (d *Dao) AddCacheUpStatDaily(c context.Context, id int64, val *model.UpStat) (err error) {
  816. if val == nil {
  817. return
  818. }
  819. conn := d.mc.Get(c)
  820. defer conn.Close()
  821. key := mcUpStatKey(id)
  822. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcUpStatDailyExpire, Flags: memcache.FlagJSON}
  823. if err = conn.Set(item); err != nil {
  824. prom.BusinessErrCount.Incr("mc:AddCacheUpStatDaily")
  825. log.Errorv(c, log.KV("AddCacheUpStatDaily", fmt.Sprintf("%+v", err)), log.KV("key", key))
  826. return
  827. }
  828. return
  829. }