fav.go 774 B

12345678910111213141516171819202122232425262728293031323334
  1. package archive
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/library/cache/redis"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _upFavTpsPrefix = "up_fav_tps_"
  10. )
  11. func keyUpFavTpsPrefix(mid int64) string {
  12. return _upFavTpsPrefix + strconv.FormatInt(mid, 10)
  13. }
  14. // FavTypes fn
  15. func (d *Dao) FavTypes(c context.Context, mid int64) (items map[string]int64, err error) {
  16. conn := d.redis.Get(c)
  17. defer conn.Close()
  18. if items, err = redis.Int64Map(conn.Do("ZRANGE", keyUpFavTpsPrefix(mid), "0", "-1", "WITHSCORES")); err != nil {
  19. log.Error("redis.Int64Map(conn.Do(ZRANGE, %s, 0, -1)) error(%v)", keyUpFavTpsPrefix(mid), err)
  20. }
  21. return
  22. }
  23. func (d *Dao) pingRedis(c context.Context) (err error) {
  24. conn := d.redis.Get(c)
  25. _, err = conn.Do("SET", "PING", "PONG")
  26. conn.Close()
  27. return
  28. }