redis.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package push
  2. import (
  3. "context"
  4. "go-common/library/cache/redis"
  5. "go-common/library/log"
  6. )
  7. const _pushKey = "appstatic-admin-topush"
  8. // ZrangeList picks up all the to push resIDs, ctime
  9. func (d *Dao) ZrangeList(c context.Context) (resIDs map[string]int64, err error) {
  10. var (
  11. conn = d.redis.Get(c)
  12. key = _pushKey
  13. )
  14. defer conn.Close()
  15. // get all the resIDs in one shot
  16. if err = conn.Send("ZRANGE", _pushKey, 0, -1, "WITHSCORES"); err != nil {
  17. log.Error("conn.Do(ZREVRANGE, %s) error(%v)", key, err)
  18. return
  19. }
  20. if err = conn.Flush(); err != nil {
  21. log.Error("conn.Flush() err(%v)", err)
  22. return
  23. }
  24. if resIDs, err = redis.Int64Map(conn.Receive()); err != nil {
  25. log.Error("redis.Int64s()err(%v)", err)
  26. return
  27. }
  28. return
  29. }
  30. // ZRem ZREM trim from trim queue.
  31. func (d *Dao) ZRem(c context.Context, resID string) (err error) {
  32. var (
  33. conn = d.redis.Get(c)
  34. key = _pushKey
  35. )
  36. if _, err = conn.Do("ZREM", key, resID); err != nil {
  37. log.Error("conn.Send(ZADD %s - %v) error(%v)", key, resID, err)
  38. }
  39. conn.Close()
  40. return
  41. }