dao.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/job/main/videoup/conf"
  5. xredis "go-common/library/cache/redis"
  6. xsql "go-common/library/database/sql"
  7. xhttp "go-common/library/net/http/blademaster"
  8. )
  9. // Dao is redis dao.
  10. type Dao struct {
  11. c *conf.Config
  12. db *xsql.DB
  13. rdb *xsql.DB
  14. coverRds *xredis.Pool
  15. coverExpire int32
  16. client *xhttp.Client
  17. statURI string
  18. recommendURI string
  19. }
  20. // New new a archive dao.
  21. func New(c *conf.Config) (d *Dao) {
  22. d = &Dao{
  23. c: c,
  24. db: xsql.NewMySQL(c.DB.Archive),
  25. rdb: xsql.NewMySQL(c.DB.ArchiveRead),
  26. coverRds: xredis.NewPool(c.Redis),
  27. coverExpire: 86400 * 15,
  28. client: xhttp.NewClient(c.HTTPClient),
  29. statURI: c.Host.API + "/x/internal/v2/archive/stat",
  30. recommendURI: c.Host.RecCover + "/cover_recomm",
  31. }
  32. return d
  33. }
  34. // BeginTran begin transcation.
  35. func (d *Dao) BeginTran(c context.Context) (tx *xsql.Tx, err error) {
  36. return d.db.Begin(c)
  37. }
  38. // Close fn
  39. func (d *Dao) Close() {
  40. d.coverRds.Close()
  41. }
  42. // Ping hbase
  43. func (d *Dao) Ping(c context.Context) (err error) {
  44. return nil
  45. }