Skip to content

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

Closed
wants to merge 4 commits into from

Conversation

doujiang24
Copy link
Member

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.

@doujiang24
Copy link
Member Author

And, now the incr with init just like safe_add, I'm not sure it's suitable enough
This is not good enough in lua-resty-traffic-limmit, maybe, we need an new api safe_incr or just force delete in incr with init?

@doujiang24
Copy link
Member Author

@agentzh I just fixed a stupid bug.
And now it will try to force remove unexpired nodes like DICT.add.
The option return value forcible won't be returned when init is not specified.


**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,
Copy link
Member

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"

Copy link
Member

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.

Copy link
Member

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".

@doujiang24
Copy link
Member Author

@agentzh Thanks for your review, fixed and rebased :)

}

/* add value */
num = value + luaL_checknumber(L, 4);
Copy link
Member

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.

Copy link
Member

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.

@agentzh
Copy link
Member

agentzh commented Jul 1, 2016

@doujiang24 Please check out my most recent comments :)

BTW, will you please update ngx_http_lua_ffi_shdict_incr too. The FFI implementation needs to be in sync. Thanks!

@doujiang24 doujiang24 force-pushed the shdict_incr branch 3 times, most recently from 12a535a to 74678d3 Compare July 4, 2016 08:10
@doujiang24
Copy link
Member Author

@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 "
Copy link
Member

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).

@agentzh
Copy link
Member

agentzh commented Jul 27, 2016

BTW, please rebase to the latest git master branch. Thank you!

@agentzh
Copy link
Member

agentzh commented Aug 8, 2016

Already merged into master.

@agentzh agentzh closed this Aug 8, 2016
@doujiang24 doujiang24 deleted the shdict_incr branch November 18, 2016 02:31
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.

2 participants