hr_store_r4.go 744 B

123456789101112131415161718192021222324252627282930313233343536
  1. package redis
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/go-redis/redis/v8"
  6. "github.com/sirupsen/logrus"
  7. "sportfitness/base/assembly/heartRate/model"
  8. )
  9. const hrStoreR4Key = prefix + ":hr_store_r4"
  10. func HrStoreR4(list []model.HrCourseDetail) {
  11. cmds, err := getClient().TxPipelined(ctx, func(pipeliner redis.Pipeliner) error {
  12. for _, one := range list {
  13. data, err2 := json.Marshal(one.HrResult)
  14. if err2 != nil {
  15. panic(err2)
  16. }
  17. pipeliner.Set(ctx, fmt.Sprintf("%s:%d", hrStoreR4Key, one.HcId), data, 0)
  18. }
  19. return nil
  20. })
  21. if err != nil {
  22. logrus.Errorf("HrStoreR4 保存失败:%s", err)
  23. return
  24. }
  25. for _, r := range cmds {
  26. if r.Err() != nil {
  27. logrus.Errorf("HrStoreR4 保存失败:%s", r.Err())
  28. }
  29. }
  30. }