mc.cache.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. //mc: -key=elecUPRankKey -type=get
  7. CacheElecUPRank(c context.Context, mid int64) (*model.ElecUPRank, error)
  8. //mc: -key=elecUPRankKey -expire=conf.Conf.CacheTTL.ElecUPRankTTL
  9. AddCacheElecUPRank(c context.Context, mid int64, value *model.ElecUPRank) error
  10. //mc: -key=elecUPRankKey
  11. DelCacheElecUPRank(c context.Context, mid int64) error
  12. //mc: -key=elecAVRankKey -type=get
  13. CacheElecAVRank(c context.Context, avID int64) (*model.ElecAVRank, error)
  14. //mc: -key=elecAVRankKey -expire=conf.Conf.CacheTTL.ElecAVRankTTL
  15. AddCacheElecAVRank(c context.Context, avID int64, value *model.ElecAVRank) error
  16. //mc: -key=elecAVRankKey
  17. DelCacheElecAVRank(c context.Context, avID int64) error
  18. //mc: -key=elecPrepUPRankKey -type=get
  19. CacheElecPrepUPRank(c context.Context, mid int64) (*model.ElecPrepUPRank, error)
  20. //mc: -key=elecPrepUPRankKey -expire=conf.Conf.CacheTTL.ElecPrepUPRankTTL
  21. AddCacheElecPrepUPRank(c context.Context, mid int64, value *model.ElecPrepUPRank) error
  22. //mc: -key=elecPrepUPRankKey
  23. DelCacheElecPrepUPRank(c context.Context, mid int64) error
  24. //mc: -key=elecPrepAVRankKey -type=get
  25. CacheElecPrepAVRank(c context.Context, avID int64) (*model.ElecPrepAVRank, error)
  26. //mc: -key=elecPrepAVRankKey -expire=conf.Conf.CacheTTL.ElecPrepAVRankTTL
  27. AddCacheElecPrepAVRank(c context.Context, avID int64, value *model.ElecPrepAVRank) error
  28. //mc: -key=elecPrepAVRankKey
  29. DelCacheElecPrepAVRank(c context.Context, avID int64) error
  30. }
  31. */
  32. package dao
  33. import (
  34. "context"
  35. "fmt"
  36. "go-common/app/service/main/ugcpay-rank/internal/conf"
  37. "go-common/app/service/main/ugcpay-rank/internal/model"
  38. "go-common/library/cache/memcache"
  39. "go-common/library/log"
  40. "go-common/library/stat/prom"
  41. )
  42. var _ _mc
  43. // CacheElecUPRank get data from mc
  44. func (d *Dao) CacheElecUPRank(c context.Context, upMID int64, ver int64) (res *model.RankElecUPProto, err error) {
  45. conn := d.mc.Get(c)
  46. defer conn.Close()
  47. key := elecUPRankKey(upMID, ver)
  48. reply, err := conn.Get(key)
  49. if err != nil {
  50. if err == memcache.ErrNotFound {
  51. err = nil
  52. return
  53. }
  54. prom.BusinessErrCount.Incr("mc:CacheElecUPRank")
  55. log.Errorv(c, log.KV("CacheElecUPRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  56. return
  57. }
  58. res = &model.RankElecUPProto{}
  59. err = conn.Scan(reply, res)
  60. if err != nil {
  61. prom.BusinessErrCount.Incr("mc:CacheElecUPRank")
  62. log.Errorv(c, log.KV("CacheElecUPRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  63. return
  64. }
  65. return
  66. }
  67. // SetCacheElecUPRank Set data to mc
  68. func (d *Dao) SetCacheElecUPRank(c context.Context, upMID, ver int64, val *model.RankElecUPProto) (err error) {
  69. if val == nil {
  70. return
  71. }
  72. conn := d.mc.Get(c)
  73. defer conn.Close()
  74. key := elecUPRankKey(upMID, ver)
  75. item := &memcache.Item{Key: key, Object: val, Expiration: conf.Conf.CacheTTL.ElecUPRankTTL, Flags: memcache.FlagProtobuf}
  76. if err = conn.Set(item); err != nil {
  77. prom.BusinessErrCount.Incr("mc:SetCacheElecUPRank")
  78. log.Errorv(c, log.KV("SetCacheElecUPRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  79. return
  80. }
  81. return
  82. }
  83. // DelCacheElecUPRank delete data from mc
  84. func (d *Dao) DelCacheElecUPRank(c context.Context, upMID, ver int64) (err error) {
  85. conn := d.mc.Get(c)
  86. defer conn.Close()
  87. key := elecUPRankKey(upMID, ver)
  88. if err = conn.Delete(key); err != nil {
  89. if err == memcache.ErrNotFound {
  90. err = nil
  91. return
  92. }
  93. prom.BusinessErrCount.Incr("mc:DelCacheElecUPRank")
  94. log.Errorv(c, log.KV("DelCacheElecUPRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  95. return
  96. }
  97. return
  98. }
  99. // CacheElecAVRank get data from mc
  100. func (d *Dao) CacheElecAVRank(c context.Context, avID, ver int64) (res *model.RankElecAVProto, err error) {
  101. conn := d.mc.Get(c)
  102. defer conn.Close()
  103. key := elecAVRankKey(avID, ver)
  104. reply, err := conn.Get(key)
  105. if err != nil {
  106. if err == memcache.ErrNotFound {
  107. err = nil
  108. return
  109. }
  110. prom.BusinessErrCount.Incr("mc:CacheElecAVRank")
  111. log.Errorv(c, log.KV("CacheElecAVRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  112. return
  113. }
  114. res = &model.RankElecAVProto{}
  115. err = conn.Scan(reply, res)
  116. if err != nil {
  117. prom.BusinessErrCount.Incr("mc:CacheElecAVRank")
  118. log.Errorv(c, log.KV("CacheElecAVRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  119. return
  120. }
  121. return
  122. }
  123. // SetCacheElecAVRank Set data to mc
  124. func (d *Dao) SetCacheElecAVRank(c context.Context, avID, ver int64, val *model.RankElecAVProto) (err error) {
  125. if val == nil {
  126. return
  127. }
  128. conn := d.mc.Get(c)
  129. defer conn.Close()
  130. key := elecAVRankKey(avID, ver)
  131. item := &memcache.Item{Key: key, Object: val, Expiration: conf.Conf.CacheTTL.ElecAVRankTTL, Flags: memcache.FlagProtobuf}
  132. if err = conn.Set(item); err != nil {
  133. prom.BusinessErrCount.Incr("mc:SetCacheElecAVRank")
  134. log.Errorv(c, log.KV("SetCacheElecAVRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  135. return
  136. }
  137. return
  138. }
  139. // DelCacheElecAVRank delete data from mc
  140. func (d *Dao) DelCacheElecAVRank(c context.Context, avID, ver int64) (err error) {
  141. conn := d.mc.Get(c)
  142. defer conn.Close()
  143. key := elecAVRankKey(avID, ver)
  144. if err = conn.Delete(key); err != nil {
  145. if err == memcache.ErrNotFound {
  146. err = nil
  147. return
  148. }
  149. prom.BusinessErrCount.Incr("mc:DelCacheElecAVRank")
  150. log.Errorv(c, log.KV("DelCacheElecAVRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  151. return
  152. }
  153. return
  154. }
  155. // CacheElecPrepUPRank get data from mc
  156. func (d *Dao) CacheElecPrepUPRank(c context.Context, upMID, ver int64) (res *model.RankElecPrepUPProto, item *memcache.Item, err error) {
  157. conn := d.mc.Get(c)
  158. defer conn.Close()
  159. key := elecPrepUPRankKey(upMID, ver)
  160. item, err = conn.Get(key)
  161. if err != nil {
  162. if err == memcache.ErrNotFound {
  163. err = nil
  164. return
  165. }
  166. prom.BusinessErrCount.Incr("mc:CacheElecPrepUPRank")
  167. log.Errorv(c, log.KV("CacheElecPrepUPRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  168. return
  169. }
  170. res = &model.RankElecPrepUPProto{}
  171. err = conn.Scan(item, res)
  172. if err != nil {
  173. prom.BusinessErrCount.Incr("mc:CacheElecPrepUPRank")
  174. log.Errorv(c, log.KV("CacheElecPrepUPRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  175. return
  176. }
  177. return
  178. }
  179. // SetCacheElecPrepUPRank Set data to mc
  180. func (d *Dao) SetCacheElecPrepUPRank(c context.Context, upMID, ver int64, val *model.RankElecPrepUPProto) (err error) {
  181. if val == nil {
  182. return
  183. }
  184. conn := d.mc.Get(c)
  185. defer conn.Close()
  186. key := elecPrepUPRankKey(upMID, ver)
  187. item := &memcache.Item{Key: key, Object: val, Expiration: conf.Conf.CacheTTL.ElecPrepUPRankTTL, Flags: memcache.FlagProtobuf}
  188. if err = conn.Set(item); err != nil {
  189. prom.BusinessErrCount.Incr("mc:SetCacheElecPrepUPRank")
  190. log.Errorv(c, log.KV("SetCacheElecPrepUPRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  191. return
  192. }
  193. return
  194. }
  195. // DelCacheElecPrepUPRank delete data from mc
  196. func (d *Dao) DelCacheElecPrepUPRank(c context.Context, upMID, ver int64) (err error) {
  197. conn := d.mc.Get(c)
  198. defer conn.Close()
  199. key := elecPrepUPRankKey(upMID, ver)
  200. if err = conn.Delete(key); err != nil {
  201. if err == memcache.ErrNotFound {
  202. err = nil
  203. return
  204. }
  205. prom.BusinessErrCount.Incr("mc:DelCacheElecPrepUPRank")
  206. log.Errorv(c, log.KV("DelCacheElecPrepUPRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  207. return
  208. }
  209. return
  210. }
  211. // CacheElecPrepAVRank get data from mc
  212. func (d *Dao) CacheElecPrepAVRank(c context.Context, avID, ver int64) (res *model.RankElecPrepAVProto, item *memcache.Item, err error) {
  213. conn := d.mc.Get(c)
  214. defer conn.Close()
  215. key := elecPrepAVRankKey(avID, ver)
  216. item, err = conn.Get(key)
  217. if err != nil {
  218. if err == memcache.ErrNotFound {
  219. err = nil
  220. return
  221. }
  222. prom.BusinessErrCount.Incr("mc:CacheElecPrepAVRank")
  223. log.Errorv(c, log.KV("CacheElecPrepAVRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  224. return
  225. }
  226. res = &model.RankElecPrepAVProto{}
  227. err = conn.Scan(item, res)
  228. if err != nil {
  229. prom.BusinessErrCount.Incr("mc:CacheElecPrepAVRank")
  230. log.Errorv(c, log.KV("CacheElecPrepAVRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  231. return
  232. }
  233. return
  234. }
  235. // SetCacheElecPrepAVRank Set data to mc
  236. func (d *Dao) SetCacheElecPrepAVRank(c context.Context, avID, ver int64, val *model.RankElecPrepAVProto) (err error) {
  237. if val == nil {
  238. return
  239. }
  240. conn := d.mc.Get(c)
  241. defer conn.Close()
  242. key := elecPrepAVRankKey(avID, ver)
  243. item := &memcache.Item{Key: key, Object: val, Expiration: conf.Conf.CacheTTL.ElecPrepAVRankTTL, Flags: memcache.FlagProtobuf}
  244. if err = conn.Set(item); err != nil {
  245. prom.BusinessErrCount.Incr("mc:SetCacheElecPrepAVRank")
  246. log.Errorv(c, log.KV("SetCacheElecPrepAVRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  247. return
  248. }
  249. return
  250. }
  251. // DelCacheElecPrepAVRank delete data from mc
  252. func (d *Dao) DelCacheElecPrepAVRank(c context.Context, avID, ver int64) (err error) {
  253. conn := d.mc.Get(c)
  254. defer conn.Close()
  255. key := elecPrepAVRankKey(avID, ver)
  256. if err = conn.Delete(key); err != nil {
  257. if err == memcache.ErrNotFound {
  258. err = nil
  259. return
  260. }
  261. prom.BusinessErrCount.Incr("mc:DelCacheElecPrepAVRank")
  262. log.Errorv(c, log.KV("DelCacheElecPrepAVRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  263. return
  264. }
  265. return
  266. }
  267. // AddCacheElecPrepAVRank Set data to mc
  268. func (d *Dao) AddCacheElecPrepAVRank(c context.Context, avID, ver int64, val *model.RankElecPrepAVProto) (ok bool, err error) {
  269. ok = true
  270. if val == nil {
  271. return
  272. }
  273. conn := d.mc.Get(c)
  274. defer conn.Close()
  275. key := elecPrepAVRankKey(avID, ver)
  276. item := &memcache.Item{Key: key, Object: val, Expiration: conf.Conf.CacheTTL.ElecPrepAVRankTTL, Flags: memcache.FlagProtobuf}
  277. if err = conn.Add(item); err != nil {
  278. if err == memcache.ErrNotStored {
  279. ok = false
  280. err = nil
  281. return
  282. }
  283. prom.BusinessErrCount.Incr("mc:AddCacheElecPrepAVRank")
  284. log.Errorv(c, log.KV("AddCacheElecPrepAVRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  285. return
  286. }
  287. return
  288. }
  289. // AddCacheElecPrepUPRank Set data to mc
  290. func (d *Dao) AddCacheElecPrepUPRank(c context.Context, upMID, ver int64, val *model.RankElecPrepUPProto) (ok bool, err error) {
  291. ok = true
  292. if val == nil {
  293. return
  294. }
  295. conn := d.mc.Get(c)
  296. defer conn.Close()
  297. key := elecPrepUPRankKey(upMID, ver)
  298. item := &memcache.Item{Key: key, Object: val, Expiration: conf.Conf.CacheTTL.ElecPrepUPRankTTL, Flags: memcache.FlagProtobuf}
  299. if err = conn.Set(item); err != nil {
  300. if err == memcache.ErrNotStored {
  301. ok = false
  302. err = nil
  303. return
  304. }
  305. prom.BusinessErrCount.Incr("mc:AddCacheElecPrepUPRank")
  306. log.Errorv(c, log.KV("AddCacheElecPrepUPRank", fmt.Sprintf("%+v", err)), log.KV("key", key))
  307. return
  308. }
  309. return
  310. }