dao.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package dao
  2. import (
  3. "context"
  4. "go-common/library/cache/redis"
  5. "go-common/library/log"
  6. "go-common/app/admin/live/live-admin/conf"
  7. relationApi "go-common/app/service/live/relation/api/liverpc"
  8. )
  9. // Dao dao
  10. type Dao struct {
  11. c *conf.Config
  12. // mc *memcache.Pool
  13. redis *redis.Pool
  14. // db *xsql.DB
  15. Relation *relationApi.Client
  16. }
  17. // New init mysql db
  18. func New(c *conf.Config) (dao *Dao) {
  19. dao = &Dao{
  20. c: c,
  21. // mc: memcache.NewPool(c.Memcache),
  22. redis: redis.NewPool(c.Redis),
  23. // db: xsql.NewMySQL(c.MySQL),
  24. Relation: relationApi.New(getConf("relation")),
  25. }
  26. return
  27. }
  28. // Close close the resource.
  29. func (d *Dao) Close() {
  30. // d.mc.Close()
  31. d.redis.Close()
  32. // d.db.Close()
  33. }
  34. // Ping dao ping
  35. func (d *Dao) Ping(ctx context.Context) (err error) {
  36. if err = d.pingRedis(ctx); err != nil {
  37. log.Error("Failed to ping redis: %v", err)
  38. }
  39. return
  40. }
  41. func (d *Dao) pingRedis(ctx context.Context) (err error) {
  42. conn := d.redis.Get(ctx)
  43. _, err = conn.Do("SET", "PING", "PONG")
  44. conn.Close()
  45. return
  46. }