hr_store_r4.go 745 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package redis
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "sportfitness/base/assembly/heartRate/model"
  6. "github.com/go-redis/redis/v8"
  7. "github.com/sirupsen/logrus"
  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.CrID), 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. }