dao.go 635 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/app-player/conf"
  5. "go-common/library/cache/memcache"
  6. "go-common/library/cache/redis"
  7. )
  8. // Dao is dao.
  9. type Dao struct {
  10. // mc
  11. mc *memcache.Pool
  12. // redis
  13. redis *redis.Pool
  14. }
  15. // New new a dao.
  16. func New(c *conf.Config) (d *Dao) {
  17. d = &Dao{
  18. // mc
  19. mc: memcache.NewPool(c.Memcache),
  20. // reids
  21. redis: redis.NewPool(c.Redis),
  22. }
  23. return
  24. }
  25. // PingMc is
  26. func (d *Dao) PingMc(c context.Context) (err error) {
  27. conn := d.mc.Get(c)
  28. item := &memcache.Item{Key: "ping", Value: []byte{1}, Flags: memcache.FlagRAW, Expiration: 0}
  29. err = conn.Set(item)
  30. conn.Close()
  31. return
  32. }