mc.cache.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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
  9. DelCacheTimeFinish(c context.Context) (int64, error)
  10. // mc: -key=timeLessKey
  11. DelCacheTimeLess(c context.Context) (int64, error)
  12. }
  13. */
  14. package bnj
  15. import (
  16. "context"
  17. "fmt"
  18. "strconv"
  19. "go-common/library/cache/memcache"
  20. "go-common/library/log"
  21. "go-common/library/stat/prom"
  22. )
  23. var _ _mc
  24. // CacheTimeFinish get data from mc
  25. func (d *Dao) CacheTimeFinish(c context.Context) (res int64, err error) {
  26. conn := d.mc.Get(c)
  27. defer conn.Close()
  28. key := timeFinishKey()
  29. reply, err := conn.Get(key)
  30. if err != nil {
  31. if err == memcache.ErrNotFound {
  32. err = nil
  33. return
  34. }
  35. prom.BusinessErrCount.Incr("mc:CacheTimeFinish")
  36. log.Errorv(c, log.KV("CacheTimeFinish", fmt.Sprintf("%+v", err)), log.KV("key", key))
  37. return
  38. }
  39. var v string
  40. err = conn.Scan(reply, &v)
  41. if err != nil {
  42. prom.BusinessErrCount.Incr("mc:CacheTimeFinish")
  43. log.Errorv(c, log.KV("CacheTimeFinish", fmt.Sprintf("%+v", err)), log.KV("key", key))
  44. return
  45. }
  46. r, err := strconv.ParseInt(v, 10, 64)
  47. if err != nil {
  48. prom.BusinessErrCount.Incr("mc:CacheTimeFinish")
  49. log.Errorv(c, log.KV("CacheTimeFinish", fmt.Sprintf("%+v", err)), log.KV("key", key))
  50. return
  51. }
  52. res = int64(r)
  53. return
  54. }
  55. // DelCacheTimeFinish delete data from mc
  56. func (d *Dao) DelCacheTimeFinish(c context.Context) (err error) {
  57. conn := d.mc.Get(c)
  58. defer conn.Close()
  59. key := timeFinishKey()
  60. if err = conn.Delete(key); err != nil {
  61. if err == memcache.ErrNotFound {
  62. err = nil
  63. return
  64. }
  65. prom.BusinessErrCount.Incr("mc:DelCacheTimeFinish")
  66. log.Errorv(c, log.KV("DelCacheTimeFinish", fmt.Sprintf("%+v", err)), log.KV("key", key))
  67. return
  68. }
  69. return
  70. }
  71. // DelCacheTimeLess delete data from mc
  72. func (d *Dao) DelCacheTimeLess(c context.Context) (err error) {
  73. conn := d.mc.Get(c)
  74. defer conn.Close()
  75. key := timeLessKey()
  76. if err = conn.Delete(key); err != nil {
  77. if err == memcache.ErrNotFound {
  78. err = nil
  79. return
  80. }
  81. prom.BusinessErrCount.Incr("mc:DelCacheTimeLess")
  82. log.Errorv(c, log.KV("DelCacheTimeLess", fmt.Sprintf("%+v", err)), log.KV("key", key))
  83. return
  84. }
  85. return
  86. }