openresty / lua-resty-limit-traffic

Lua library for limiting and controlling traffic in OpenResty/ngx_lua
819 stars 150 forks source link

an advise #8

Open yitony opened 8 years ago

yitony commented 8 years ago

on line 114 of req.lua

   111     if commit then
112         rec_cdata.excess = excess
113         rec_cdata.last = now
114         dict:set(key, ffi_str(rec_cdata, rec_size))
115     end

I think it will save mem if you set a expire time on the key, like below dict:set(key, ffi_str(rec_cdata, rec_size),60)

same advise on con.lua ,but you need to change add to set

also ,I can't figure out the uncommit mechanism in req.lua ,where and when should I call uncommit?

agentzh commented 8 years ago

@yitony Yes, setting an exptime helps saving shm storage in some cases. Will you create a pull request for that? Thanks!

Regarding the uncommit method, it is documented (well, I've just fixed a typo in the docs and added some more stuff):

https://github.com/openresty/lua-resty-limit-traffic/blob/master/lib/resty/limit/req.md#uncommit