dao.go 969 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/web-feed/conf"
  6. "go-common/library/cache/memcache"
  7. "go-common/library/stat/prom"
  8. )
  9. // Dao .
  10. type Dao struct {
  11. c *conf.Config
  12. mc *memcache.Pool
  13. mcFeedExpire int32
  14. }
  15. var (
  16. errorsCount = prom.BusinessErrCount
  17. infosCount = prom.BusinessInfoCount
  18. )
  19. // PromError prom error
  20. func PromError(name string) {
  21. errorsCount.Incr(name)
  22. }
  23. // PromInfo add prom info
  24. func PromInfo(name string) {
  25. infosCount.Incr(name)
  26. }
  27. // New add a feed job dao.
  28. func New(c *conf.Config) (d *Dao) {
  29. d = &Dao{
  30. c: c,
  31. mc: memcache.NewPool(c.Memcache.Config),
  32. mcFeedExpire: int32(time.Duration(c.Memcache.FeedExpire) / time.Second),
  33. }
  34. return
  35. }
  36. // Ping checks health of redis and mc.
  37. func (d *Dao) Ping(c context.Context) (err error) {
  38. return d.pingMC(c)
  39. }
  40. // Close closes connections of redis or mc etc.
  41. func (d *Dao) Close() {
  42. if d.mc != nil {
  43. d.mc.Close()
  44. }
  45. }