Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

防止请求重发的中间件 #233

Open
RanKKI opened this issue Oct 6, 2022 · 3 comments
Open

防止请求重发的中间件 #233

RanKKI opened this issue Oct 6, 2022 · 3 comments

Comments

@RanKKI
Copy link
Member

RanKKI commented Oct 6, 2022

用户发送请求 A,出于某些原因超时,客户端没有接收到返回。用户选择重发请求,产生请求 B。
服务器会在某个时间范围内收到 A,B 两个一样的请求,理论上应该 drop 第二个请求。

目前似乎没有这个机制,

可以对请求的 url ,数据和用户 id,hash一下存到 redis 并设置过期时间 比如 1分钟,在接到第二个请求就直接返回错误。

之前甚至搞过缓存第一个请求的结果,用户在单位时间内再次请求会返回缓存的结果

前提自然是第一个请求服务器确实接收到了

ps: 当然不对 GET 请求生效

@trim21
Copy link
Contributor

trim21 commented Oct 6, 2022

感觉好像没太大必要…

@RanKKI
Copy link
Member Author

RanKKI commented Oct 7, 2022

就怕因为网络问题导致创建两份一样数据

@banafish
Copy link

banafish commented Jan 9, 2023

一些关键接口写成幂等就行了吧,像查询这些本身就幂等,请求重发也没影响

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants