Skip to content

Commit

Permalink
fix: 修复BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
Lansongxx committed Apr 17, 2024
1 parent 3828411 commit f6761f0
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions biz/application/service/hot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/zeromicro/go-zero/core/stores/redis"
"go.mongodb.org/mongo-driver/bson/primitive"
"math"
"strconv"
"time"
)

Expand Down Expand Up @@ -120,15 +119,21 @@ func (s *HotService) IncrHotValue(ctx context.Context, req *gencontent.IncrHotVa
//}
flag = true
if flag {
val, err := s.Redis.EvalCtx(ctx, luaScript, []string{rankKey}, []any{nowHot, req.HotId})
if err != nil {
return resp, err
//val, err := s.Redis.EvalCtx(ctx, luaScript, []string{rankKey}, []any{nowHot, req.HotId})
//if err != nil {
// return resp, err
//}
_, _ = s.Redis.ZaddFloatCtx(ctx, rankKey, nowHot, req.HotId)
sz, _ := s.Redis.ZcardCtx(ctx, rankKey)
if sz > 100 {
// sz - 100
_, _ = s.Redis.ZremrangebyrankCtx(ctx, rankKey, 0, int64(sz-101))
}
lastRank, err := strconv.ParseFloat(val.([]any)[1].(string), 64)
if err != nil {
return resp, err
}
s.Cache.SetWithExpire(rankKey, lastRank, time.Duration(s.Config.HotServiceConf.RankKeyExpire)*time.Second)
//lastRank, err := strconv.ParseFloat(val.([]any)[1].(string), 64)
//if err != nil {
// return resp, err
//}
//s.Cache.SetWithExpire(rankKey, lastRank, time.Duration(s.Config.HotServiceConf.RankKeyExpire)*time.Second)
}

if err = s.HotMongoMapper.Update(ctx, &hotmapper.Hot{
Expand Down

0 comments on commit f6761f0

Please sign in to comment.