-
Notifications
You must be signed in to change notification settings - Fork 2k
ngx.shared.DICT.incr optional expire argument #358
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
Conversation
Can I bump this? Its an extremely simple patch for a feature I continue to find to be very useful. Primarily we use this in systems with timed states (e.g bans) based on keys stored into shared memory. Merges cleanly into latest master. |
if (n != 3) { | ||
return luaL_error(L, "expecting 3 arguments, but only seen %d", n); | ||
if (n < 3) { | ||
return luaL_error(L, "expecting atleast 3 arguments, but only seen %d", n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: atleast => at least
@splitice Sorry for the delay on my side. Feel free to bump tickets lacking my replies :) In addition to the issues commented above, will you please add some unit test cases for this new feature in the existing test suite? Or even better, some some simple docs in the file |
Thank you for the feedback, I have updated the pull request to include the recommendations given (with the exception of a unit test). I am not confident in my understanding of the unit testing system used, nor do I currently have the testing environment configured. It should not be difficult to add as the semantics are the same as with other methods including the parameter. |
return luaL_error(L, "expecting at least 3 arguments, but only seen %d", n); | ||
} | ||
|
||
if (n > 4) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: indentation not aligned. Maybe you're using a tab here?
Also, I think we can merge these two tests into a single test (see other functions).
@splitice The documentation for the test scaffold can be found here: https://github.com/openresty/lua-nginx-module#test-suite https://github.com/openresty/test-nginx#readme And I usually use the |
Fixed the stray tab. Added better parameter handling, now accepts |
Conflicts: src/ngx_http_lua_shdict.c
Related #586 |
Shdict cas
# Conflicts: # doc/HttpLuaModule.wiki # src/ngx_http_lua_shdict.c
I wonder if we can just add an |
yeah, I think |
I still feel that the incr method should match the syntax of set and add which both have an expire argument. And at-least in our use-cases for the shared dictionary (primarily as a keyed hit counter, or cache) we use expires for near every call. Although its going to be difficult to get consistency now that the init parameter has been introduced :( This PR has conflicts and has got messy (since it was based off our master years ago) at the moment, I'll resolve them if this ever looks likely to merge. |
@doujiang24 Separate nginx C module? I don't think we are there yet :) Better be in the lua-nginx-module core now. We can split the subsystems systematically later. |
@splitice |
Sorry, i'm not sure I really see your point regarding existing keys. At-least in our usages of incr over multiple subsystems I can count on one hand the number of times we have used In order to do this with two methods expire would have to return false if the key was not found, and then incr called with init, then if created call expire again. Three method calls (worst-case) for something we currently do with one parameter (and one rbtree lookup). I have no objections for an exipre method as well. its definitely a plus. Theres a few places we do |
@splitice Your PR's diff contains unrelated changes like |
Yes, as stated this would require work before merging now. I never expected it to sit around for 2-3 years. I'll make a feature branch and re-order the parameters (we are using key, value, expire, init since for us expire came first, and its more consistent with set & add) Heres what we currently use almost everywhere:
Heres what it would become:
|
@splitice Well, we could add an optional |
This Pull request adds an |
@splitice Just a reminder: to make your PR merge-able, you'll have to
The last time I checked, this PR lacks test cases at least. |
@splitice Thanks for your contribution! |
All APIs (FFI & CFunction) have been built and work (we have used them for years), they just need to be rebased to a newer version and their arguments order switched for backwards compatibility. There is a corresponding lua-resty-core patch. If this will get merged I'll write a simple set tests, Something like:
If this is sufficient, I'll do the work. Otherwise if there is still debate over the feature, I'll leave it. |
@splitice The API design looks good to me from your test draft. @doujiang24 @membphis @moonbingbing ? BTW, newly added tests should use |
LGME:) |
LGTM |
LGME :) |
As mentioned in https://groups.google.com/forum/#!topic/openresty-en/-avsa-jaSYg