golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
925 B

  1. package repo
  2. import (
  3. "gim/pkg/db"
  4. "gim/pkg/gerrors"
  5. "strconv"
  6. )
  7. const (
  8. DeviceACKKey = "device_ack:"
  9. )
  10. type deviceACKRepo struct{}
  11. var DeviceACKRepo = new(deviceACKRepo)
  12. // Set 设置设备同步序列号
  13. func (c *deviceACKRepo) Set(userId int64, deviceId int64, ack int64) error {
  14. _, err := db.RedisCli.HSet(DeviceACKKey+strconv.FormatInt(userId, 10), strconv.FormatInt(deviceId, 10),
  15. strconv.FormatInt(ack, 10)).Result()
  16. if err != nil {
  17. return gerrors.WrapError(err)
  18. }
  19. return nil
  20. }
  21. func (c *deviceACKRepo) Get(userId int64) (map[int64]int64, error) {
  22. result, err := db.RedisCli.HGetAll(DeviceACKKey + strconv.FormatInt(userId, 10)).Result()
  23. if err != nil {
  24. return nil, gerrors.WrapError(err)
  25. }
  26. acks := make(map[int64]int64, len(result))
  27. for k, v := range result {
  28. deviceId, _ := strconv.ParseInt(k, 10, 64)
  29. ack, _ := strconv.ParseInt(v, 10, 64)
  30. acks[deviceId] = ack
  31. }
  32. return acks, nil
  33. }