dao.go 637 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package databus
  2. import (
  3. "context"
  4. "go-common/app/service/main/videoup/conf"
  5. "go-common/library/cache/redis"
  6. "go-common/library/log"
  7. )
  8. // Dao is redis dao.
  9. type Dao struct {
  10. c *conf.Config
  11. // redis
  12. redis *redis.Pool
  13. }
  14. //New .
  15. func New(c *conf.Config) (d *Dao) {
  16. d = &Dao{
  17. c: c,
  18. redis: redis.NewPool(c.Redis.Track.Config),
  19. }
  20. return d
  21. }
  22. // Ping ping redis.
  23. func (d *Dao) Ping(c context.Context) (err error) {
  24. conn := d.redis.Get(c)
  25. if _, err = conn.Do("SET", "ping", "pong"); err != nil {
  26. log.Error("conn.Do(SET) error(%v)", err)
  27. }
  28. conn.Close()
  29. return
  30. }
  31. //Close .
  32. func (d *Dao) Close() {
  33. d.redis.Close()
  34. }