dao.go 544 B

1234567891011121314151617181920212223242526272829303132333435
  1. package foo
  2. import (
  3. "context"
  4. "go-common/app/interface/live/live-demo/conf"
  5. "go-common/library/cache/redis"
  6. )
  7. // Dao dao
  8. type Dao struct {
  9. c *conf.Config
  10. redis *redis.Pool
  11. }
  12. // New init
  13. func New(c *conf.Config) (dao *Dao) {
  14. dao = &Dao{
  15. c: c,
  16. redis: redis.NewPool(c.Redis),
  17. }
  18. return
  19. }
  20. // Close close the resource.
  21. func (d *Dao) Close() {
  22. d.redis.Close()
  23. }
  24. // Ping dao ping
  25. func (d *Dao) Ping(c context.Context) error {
  26. // TODO: if you need use mc,redis, please add
  27. _, err := d.redis.Get(c).Do("ping")
  28. return err
  29. }