mc.cache.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
  2. /*
  3. Package bnj is a generated mc cache package.
  4. It is generated from:
  5. type _mc interface {
  6. // mc: -key=timeFinishKey
  7. CacheTimeFinish(c context.Context) (int64, error)
  8. // mc: -key=timeFinishKey -expire=d.timeFinishExpire -encode=raw
  9. AddCacheTimeFinish(c context.Context, value int64) error
  10. // mc: -key=lessTimeKey
  11. CacheLessTime(c context.Context) (int64, error)
  12. // mc: -key=lessTimeKey -expire=d.lessTimeExpire -encode=raw
  13. AddCacheLessTime(c context.Context, value int64) error
  14. }
  15. */
  16. package bnj
  17. import (
  18. "context"
  19. "fmt"
  20. "strconv"
  21. "go-common/library/cache/memcache"
  22. "go-common/library/log"
  23. "go-common/library/stat/prom"
  24. )
  25. var _ _mc
  26. // CacheTimeFinish get data from mc
  27. func (d *Dao) CacheTimeFinish(c context.Context) (res int64, err error) {
  28. conn := d.mc.Get(c)
  29. defer conn.Close()
  30. key := timeFinishKey()
  31. reply, err := conn.Get(key)
  32. if err != nil {
  33. if err == memcache.ErrNotFound {
  34. err = nil
  35. return
  36. }
  37. prom.BusinessErrCount.Incr("mc:CacheTimeFinish")
  38. log.Errorv(c, log.KV("CacheTimeFinish", fmt.Sprintf("%+v", err)), log.KV("key", key))
  39. return
  40. }
  41. var v string
  42. err = conn.Scan(reply, &v)
  43. if err != nil {
  44. prom.BusinessErrCount.Incr("mc:CacheTimeFinish")
  45. log.Errorv(c, log.KV("CacheTimeFinish", fmt.Sprintf("%+v", err)), log.KV("key", key))
  46. return
  47. }
  48. r, err := strconv.ParseInt(v, 10, 64)
  49. if err != nil {
  50. prom.BusinessErrCount.Incr("mc:CacheTimeFinish")
  51. log.Errorv(c, log.KV("CacheTimeFinish", fmt.Sprintf("%+v", err)), log.KV("key", key))
  52. return
  53. }
  54. res = int64(r)
  55. return
  56. }
  57. // AddCacheTimeFinish Set data to mc
  58. func (d *Dao) AddCacheTimeFinish(c context.Context, val int64) (err error) {
  59. conn := d.mc.Get(c)
  60. defer conn.Close()
  61. key := timeFinishKey()
  62. bs := []byte(strconv.FormatInt(int64(val), 10))
  63. item := &memcache.Item{Key: key, Value: bs, Expiration: d.timeFinishExpire, Flags: memcache.FlagRAW}
  64. if err = conn.Set(item); err != nil {
  65. prom.BusinessErrCount.Incr("mc:AddCacheTimeFinish")
  66. log.Errorv(c, log.KV("AddCacheTimeFinish", fmt.Sprintf("%+v", err)), log.KV("key", key))
  67. return
  68. }
  69. return
  70. }
  71. // CacheLessTime get data from mc
  72. func (d *Dao) CacheLessTime(c context.Context) (res int64, err error) {
  73. conn := d.mc.Get(c)
  74. defer conn.Close()
  75. key := lessTimeKey()
  76. reply, err := conn.Get(key)
  77. if err != nil {
  78. if err == memcache.ErrNotFound {
  79. err = nil
  80. return
  81. }
  82. prom.BusinessErrCount.Incr("mc:CacheLessTime")
  83. log.Errorv(c, log.KV("CacheLessTime", fmt.Sprintf("%+v", err)), log.KV("key", key))
  84. return
  85. }
  86. var v string
  87. err = conn.Scan(reply, &v)
  88. if err != nil {
  89. prom.BusinessErrCount.Incr("mc:CacheLessTime")
  90. log.Errorv(c, log.KV("CacheLessTime", fmt.Sprintf("%+v", err)), log.KV("key", key))
  91. return
  92. }
  93. r, err := strconv.ParseInt(v, 10, 64)
  94. if err != nil {
  95. prom.BusinessErrCount.Incr("mc:CacheLessTime")
  96. log.Errorv(c, log.KV("CacheLessTime", fmt.Sprintf("%+v", err)), log.KV("key", key))
  97. return
  98. }
  99. res = int64(r)
  100. return
  101. }
  102. // AddCacheLessTime Set data to mc
  103. func (d *Dao) AddCacheLessTime(c context.Context, val int64) (err error) {
  104. conn := d.mc.Get(c)
  105. defer conn.Close()
  106. key := lessTimeKey()
  107. bs := []byte(strconv.FormatInt(int64(val), 10))
  108. item := &memcache.Item{Key: key, Value: bs, Expiration: d.lessTimeExpire, Flags: memcache.FlagRAW}
  109. if err = conn.Set(item); err != nil {
  110. prom.BusinessErrCount.Incr("mc:AddCacheLessTime")
  111. log.Errorv(c, log.KV("AddCacheLessTime", fmt.Sprintf("%+v", err)), log.KV("key", key))
  112. return
  113. }
  114. return
  115. }