Skip to content

new module resty.limit.count #17

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

Closed
wants to merge 2 commits into from

Conversation

shawnzhu
Copy link
Contributor

fixes #16

Copy link

@tangjn tangjn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The slip-up for struct name, and some other suggestions.

-- TODO: we could avoid the tricky FFI cdata when lua_shared_dict supports
-- hash-typed values as in redis.
ffi.cdef[[
struct lua_resty_limit_ghe_req_rec {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to be: struct lua_resty_limit_count_rec {

return nil, "shdict abused by other users"
end
local rec = ffi_cast(const_rec_ptr_type, v)
local ttl = tonumber(rec.reset) - now
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For tonumber(rec.reset) show 2 times, could you change to current way:
`

    local rec = ffi_cast(const_rec_ptr_type, v)
    reset = tonumber(rec.reset)
    local ttl = reset - now

    -- print("ttl: ", ttl, "s")

    if ttl > 0 then
        remaining = tonumber(rec.remaining) - 1
    else
        reset = now + window
        remaining = limit
    end

`

remaining = tonumber(rec.remaining) - 1
else
reset = now + window
remaining = limit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be: remaining = limit -1
Because initial remaining will triger by user access, so current access will using 1 access. So that need to be: limit -1

@agentzh
Copy link
Member

agentzh commented Sep 1, 2017

@tangjn Thank you for your review.

Also need some test cases in the existing test suite to cover this new module.

local setmetatable = setmetatable
local ffi_cast = ffi.cast
local ffi_str = ffi.string
local abs = math.abs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used variable

local rec = ffi_cast(const_rec_ptr_type, v)
local remaining = tonumber(rec.remaining) + 1

rec_cdata.remaining = min(remaining, limit)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be math.min.

local limit_count = require "resty.limit.count"

-- rate: 5000 requests per 3600s
local lim, err = limit_count.new("api_limit_count_store", 5000, 3600)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name of shared dict should be my_limit_count_store.

@agentzh
Copy link
Member

agentzh commented Sep 22, 2017

#21 supersedes this and has already merged into master. Closing this. Thanks!

@agentzh agentzh closed this Sep 22, 2017
@shawnzhu shawnzhu deleted the github-rate-limit branch December 27, 2017 15:33
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

Successfully merging this pull request may close these issues.

new feature to implement GitHub style request rate limit
4 participants