dao.go 838 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package share
  2. import (
  3. "context"
  4. "go-common/library/cache/redis"
  5. "go-common/library/queue/databus"
  6. "go-common/app/service/main/archive/conf"
  7. )
  8. // Dao is share dao.
  9. type Dao struct {
  10. c *conf.Config
  11. // redis
  12. rds *redis.Pool
  13. expire int32
  14. // databus
  15. statDbus *databus.Databus
  16. shareDbus *databus.Databus
  17. }
  18. // New new a share dao.
  19. func New(c *conf.Config) (d *Dao) {
  20. d = &Dao{
  21. c: c,
  22. rds: redis.NewPool(c.Redis.Archive.Config),
  23. expire: 168 * 60 * 60,
  24. statDbus: databus.New(c.StatDatabus),
  25. shareDbus: databus.New(c.ShareDatabus),
  26. }
  27. return d
  28. }
  29. // Close close resource.
  30. func (d *Dao) Close() {
  31. if d.rds != nil {
  32. d.rds.Close()
  33. }
  34. }
  35. // Ping ping success.
  36. func (d *Dao) Ping(c context.Context) (err error) {
  37. conn := d.rds.Get(c)
  38. _, err = conn.Do("SET", "PING", "PONG")
  39. conn.Close()
  40. return
  41. }