dao.go 811 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/live/live-dm/conf"
  5. "go-common/library/cache/redis"
  6. "go-common/library/sync/pipeline/fanout"
  7. )
  8. // Dao dao
  9. type Dao struct {
  10. c *conf.Config
  11. redis *redis.Pool
  12. whitelistredis *redis.Pool
  13. Databus *fanout.Fanout
  14. }
  15. // New init mysql db
  16. func New(c *conf.Config) (dao *Dao) {
  17. dao = &Dao{
  18. c: c,
  19. redis: redis.NewPool(c.Redis),
  20. whitelistredis: redis.NewPool(c.WhiteListRedis),
  21. Databus: fanout.New("dmDatabus", fanout.Worker(1), fanout.Buffer(c.CacheDatabus.Size)),
  22. }
  23. return
  24. }
  25. // Close close the resource.
  26. func (d *Dao) Close() {
  27. d.redis.Close()
  28. d.Databus.Close()
  29. d.whitelistredis.Close()
  30. }
  31. // Ping dao ping
  32. func (d *Dao) Ping(c context.Context) error {
  33. // TODO: redis
  34. return nil
  35. }