query.go 794 B

1234567891011121314151617181920212223242526272829303132
  1. package edb_source
  2. import (
  3. "context"
  4. jsoniter "github.com/json-iterator/go"
  5. "hongze/hongze_yb/global"
  6. "hongze/hongze_yb/utils"
  7. "strconv"
  8. "time"
  9. )
  10. func GetEdbSourceBySource(source int) (item *EdbSource, err error) {
  11. cacheKey := utils.HONGZEYB_EBD_SOURCE + strconv.Itoa(source)
  12. sourceInfo, _ := global.Redis.Get(context.TODO(), cacheKey).Result()
  13. if sourceInfo != "" {
  14. err = jsoniter.UnmarshalFromString(sourceInfo, &item)
  15. if err != nil {
  16. return
  17. }
  18. return
  19. } else {
  20. err = global.MYSQL["data"].Where("edb_source_id = ? ", source).First(&item).Error
  21. if err == nil && item.EdbSourceId > 0 {
  22. sourceInfo, err = jsoniter.MarshalToString(item)
  23. if err != nil {
  24. return
  25. }
  26. _ = global.Redis.SetEX(context.TODO(), cacheKey, sourceInfo, 24*time.Hour)
  27. }
  28. }
  29. return
  30. }