mc.cache.go 28 KB

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