-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feature: ngx.shared.dict add an option arg init #579
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
And, now the incr with init just like |
@agentzh I just fixed a stupid bug. |
17fd14c
to
f16d6aa
Compare
e7ac10c
to
cfd4f90
Compare
|
||
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.** | ||
|
||
Increments the (numerical) value for `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict) by the step value `value`. Returns the new resulting number if the operation is successfully completed or `nil` and an error message otherwise. | ||
|
||
The key must already exist in the dictionary, otherwise it will return `nil` and `"not found"`. | ||
When the key is not exist in the dictionary and if `init` argument, |
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.
grammar: "is not exist" => "does not exist"
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.
grammar: the trailing comma looks wrong to me.
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.
grammar; "if init
argument" => "if the init
argument".
@agentzh Thanks for your review, fixed and rebased :) |
} | ||
|
||
/* add value */ | ||
num = value + luaL_checknumber(L, 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.
The luaL_checknumber
function may throw an exception, leaving the shm mutex locked.
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.
We should check for the init argument earlier, before acquiring the lock.
@doujiang24 Please check out my most recent comments :) BTW, will you please update |
12a535a
to
74678d3
Compare
@agentzh Fixed & rebased :) |
|
||
if ((size_t) sd->value_len == sizeof(double)) { | ||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ctx->log, 0, | ||
"lua shared dict incr: found old entry and value " |
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: exceeded 80 columns (found by ngx-releng
).
BTW, please rebase to the latest git master branch. Thank you! |
Already merged into master. |
incr add an option argument initial value When the key is not exist in the dictionary and if init argument, 1) is not specified, it will return nil and "not found", 2) is specified, it will create a new key with the new value: value + init.
This is usefull when we used it as an counter.