Browse Source

使用redis优化

master
maziyang 7 days ago
parent
commit
9a0dd6dfe2
  1. 1
      api/vote_record/v1/vote_record.go
  2. 12
      internal/logic/vote_record/add_record.go

1
api/vote_record/v1/vote_record.go

@ -74,6 +74,7 @@ type GetIndexRes struct {
type AddRecordReq struct {
g.Meta `path:"/addRecord" method:"post" dc:"<UNK>"`
ArticleId int ` v:"required" json:"articleId" dc:"<<UNK>ID>"`
UserId int `v:"required" json:"userId" dc:"<用户>ID"`
VoteId int `v:"required" json:"voteId" dc:"<投票活动>ID"`
OptionId []int `v:"required" json:"optionId" dc:"<投票选项>ID"`

12
internal/logic/vote_record/add_record.go

@ -3,6 +3,7 @@ package vote_record
import (
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
v1 "practice_ArticleVote_Go/api/vote_record/v1"
"practice_ArticleVote_Go/internal/consts"
@ -28,10 +29,13 @@ func (l *VoteRecordLogic) AddRecord(ctx context.Context, req *v1.AddRecordReq) (
if err != nil {
return nil, err
}
voteDetailpattern := fmt.Sprintf(consts.VOTE_DETAIL+":%d:*", req.VoteId)
_, err = utils.DeleteKeys(ctx, voteDetailpattern)
ExportFilepattern := fmt.Sprintf(consts.EXPORT_FILE+":%d:*", req.VoteId)
_, err = utils.DeleteKeys(ctx, ExportFilepattern)
voteDetailPattern := fmt.Sprintf(consts.VOTE_DETAIL+":%d:*", req.VoteId)
_, err = utils.DeleteKeys(ctx, voteDetailPattern)
exportFilePattern := fmt.Sprintf(consts.EXPORT_FILE+":%d:*", req.VoteId)
_, err = utils.DeleteKeys(ctx, exportFilePattern)
articleAndVote := fmt.Sprintf(consts.ARTICLE+":%d", req.ArticleId)
redis := g.Redis()
_, err = redis.Del(ctx, articleAndVote)
res = &v1.AddRecordRes{}
return res, nil
}
Loading…
Cancel
Save