dao.go 753 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package video
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/favorite/conf"
  6. xredis "go-common/library/cache/redis"
  7. )
  8. // Dao defeine fav Dao
  9. type Dao struct {
  10. redisPool *xredis.Pool
  11. expireRedis int
  12. coverExpireRedis int
  13. }
  14. // New return fav dao
  15. func New(c *conf.Config) (d *Dao) {
  16. d = &Dao{
  17. redisPool: xredis.NewPool(c.Redis.Config),
  18. expireRedis: int(time.Duration(c.Redis.Expire) / time.Second),
  19. coverExpireRedis: int(time.Duration(c.Redis.CoverExpire) / time.Second),
  20. }
  21. return
  22. }
  23. // Close close all connection
  24. func (d *Dao) Close() {
  25. if d.redisPool != nil {
  26. d.redisPool.Close()
  27. }
  28. }
  29. // Ping check connection used in dao
  30. func (d *Dao) Ping(c context.Context) (err error) {
  31. return d.pingRedis(c)
  32. }