fix: ensure automic operation in limit-count plugin#3991
Merged
Conversation
ychdesign
marked this pull request as draft
April 6, 2021 09:52
ychdesign
marked this pull request as ready for review
April 6, 2021 09:59
ychdesign
marked this pull request as draft
April 6, 2021 10:03
ychdesign
marked this pull request as ready for review
April 6, 2021 10:40
spacewander
reviewed
Apr 7, 2021
| if not ret then | ||
| return nil, err | ||
| end | ||
| local remaining,err = red:eval(script,1,key,limit,window) |
Member
There was a problem hiding this comment.
Need a space around the operator. Please fix other similar places.
| return setmetatable(self, mt) | ||
| end | ||
|
|
||
| local script = "if redis.call('ttl',KEYS[1]) < 0 then " |
Member
There was a problem hiding this comment.
Would it be better to use exists instead of ttl?
Contributor
Author
There was a problem hiding this comment.
I think ttl is better. ttl will set the expire time on the key which is permanent. Both are O(1) Time complexity.
ychdesign
marked this pull request as draft
April 7, 2021 03:55
ychdesign
marked this pull request as ready for review
April 7, 2021 04:35
spacewander
approved these changes
Apr 7, 2021
tokers
reviewed
Apr 7, 2021
| } | ||
|
|
||
|
|
||
| local script = "if redis.call('ttl', KEYS[1]) < 0 then " |
Contributor
There was a problem hiding this comment.
What about using long string quotes.
local scripts [=[ .... ]=]| } | ||
|
|
||
|
|
||
| local script = "if redis.call('ttl', KEYS[1]) < 0 then " |
ychdesign
marked this pull request as draft
April 7, 2021 12:50
ychdesign
marked this pull request as ready for review
April 7, 2021 13:27
moonming
approved these changes
Apr 8, 2021
spacewander
added a commit
to spacewander/incubator-apisix
that referenced
this pull request
Apr 19, 2021
Close apache#3988 Signed-off-by: spacewander <[email protected]>
Yiyiyimu
pushed a commit
that referenced
this pull request
Apr 19, 2021
Signed-off-by: spacewander <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
Use redis's eval() to ensure atomic operations of ttl and incrby, and solve the situation where a small number of requests are accidentally killed in high concurrency scenarios
使用redis的eval()确保ttl和incrby的原子性操作,解决高并发场景下少量请求被误杀的情况
Pre-submission checklist: