feat: 增加分布式锁,防止重复提交
This commit is contained in:
parent
a4bff4284a
commit
e9cd6876c2
@ -34,6 +34,18 @@ func CreateCompetitiveReport(ctx *gin.Context) {
|
|||||||
service.Error(ctx, err)
|
service.Error(ctx, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loginInfo := login.GetUserInfoFromC(ctx)
|
||||||
|
lockKey := fmt.Sprintf("lock_create_competitive_report_%d", loginInfo.ID)
|
||||||
|
reply := cache.RedisClient.SetNX(lockKey, time.Now().Format("2006-01-02 15:04:05"), time.Second*5)
|
||||||
|
if !reply.Val() {
|
||||||
|
service.Error(ctx, errors.New("请勿重复提交"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
cache.RedisClient.Del(lockKey)
|
||||||
|
}()
|
||||||
|
|
||||||
newCtx := NewCtxWithUserInfo(ctx)
|
newCtx := NewCtxWithUserInfo(ctx)
|
||||||
artistID, _ := strconv.ParseUint(req.ArtistID, 10, 64)
|
artistID, _ := strconv.ParseUint(req.ArtistID, 10, 64)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user