redis.go 673 B

1234567891011121314151617181920212223242526272829303132
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/library/log"
  6. )
  7. const _pushKey = "appstatic-admin-topush"
  8. // ZAddPush adds one to push data into the redis sorted set
  9. func (d *Dao) ZAddPush(c context.Context, resID int) (err error) {
  10. var (
  11. conn = d.redis.Get(c)
  12. ctime = time.Now().Unix()
  13. )
  14. defer conn.Close()
  15. if err = conn.Send("ZADD", _pushKey, ctime, resID); err != nil {
  16. log.Error("conn.Send(ZADD %s - %v) error(%v)", _pushKey, resID, err)
  17. return
  18. }
  19. if err = conn.Flush(); err != nil {
  20. log.Error("conn.Flush() error(%v)", err)
  21. return
  22. }
  23. if _, err = conn.Receive(); err != nil {
  24. log.Error("conn.Receive() error(%v)", err)
  25. return
  26. }
  27. return
  28. }