-
Notifications
You must be signed in to change notification settings - Fork 2k
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
New atomic functions(cas, cog) for shm #1955
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3581,10 +3581,12 @@ Nginx API for Lua | |
* [ngx.shared.DICT](#ngxshareddict) | ||
* [ngx.shared.DICT.get](#ngxshareddictget) | ||
* [ngx.shared.DICT.get_stale](#ngxshareddictget_stale) | ||
* [ngx.shared.DICT](#ngxshareddict) | ||
* [ngx.shared.DICT.set](#ngxshareddictset) | ||
* [ngx.shared.DICT.safe_set](#ngxshareddictsafe_set) | ||
* [ngx.shared.DICT.add](#ngxshareddictadd) | ||
* [ngx.shared.DICT.safe_add](#ngxshareddictsafe_add) | ||
* [ngx.shared.DICT.cas](#ngxshareddictcas) | ||
* [ngx.shared.DICT.replace](#ngxshareddictreplace) | ||
* [ngx.shared.DICT.delete](#ngxshareddictdelete) | ||
* [ngx.shared.DICT.incr](#ngxshareddictincr) | ||
|
@@ -6784,10 +6786,12 @@ The resulting object `dict` has the following methods: | |
|
||
* [get](#ngxshareddictget) | ||
* [get_stale](#ngxshareddictget_stale) | ||
* [get_if_not_eq](#ngxshareddictget_if_not_eq) | ||
* [set](#ngxshareddictset) | ||
* [safe_set](#ngxshareddictsafe_set) | ||
* [add](#ngxshareddictadd) | ||
* [safe_add](#ngxshareddictsafe_add) | ||
* [cas](#ngxshareddictcas) | ||
* [replace](#ngxshareddictreplace) | ||
* [delete](#ngxshareddictdelete) | ||
* [incr](#ngxshareddictincr) | ||
|
@@ -6912,6 +6916,26 @@ See also [ngx.shared.DICT](#ngxshareddict). | |
|
||
[Back to TOC](#nginx-api-for-lua) | ||
|
||
ngx.shared.DICT | ||
--------------- | ||
**syntax:** *value, flags = ngx.shared.DICT:get_if_not_eq(key, old_value?, old_flags?)* | ||
|
||
**context:** *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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua** | ||
|
||
Similar to the [get](#ngxshareddictget) method, but only returns if | ||
`old_value` or `old_flags` do not match. | ||
|
||
If `old_value` or `old_flags` is `nil` | ||
it will be ignored when comparing. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This semantics does not feel right to me. When old value is nil, then it means the expected value in the shdict should also be nil. It should not get ignored? So it always return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function first lookups the key, and if cant find it return The reason for the "don't compare For Its also the fact that flags cannot exist if value is Having different logic where only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When old value is nil, it should be ignored when comparing (so value could be anything), when old flag is nil, flag is ignored. |
||
|
||
In case of match, `nil, false` will be returned. | ||
|
||
This method was first introduced in the `0.10.21` release. | ||
|
||
See also [ngx.shared.DICT](#ngxshareddict). | ||
|
||
[Back to TOC](#nginx-api-for-lua) | ||
|
||
ngx.shared.DICT.set | ||
------------------- | ||
|
||
|
@@ -7012,6 +7036,28 @@ See also [ngx.shared.DICT](#ngxshareddict). | |
|
||
[Back to TOC](#nginx-api-for-lua) | ||
|
||
ngx.shared.DICT.cas | ||
------------------- | ||
**syntax:** *success, err, forcible = ngx.shared.DICT:cas(key, old_value?, old_flags?, value?, flags?, exptime?)* | ||
|
||
**context:** *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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua** | ||
|
||
Conditionally sets key-value pair in shm. | ||
|
||
If `old_value` or `old_flags` is `nil` it will | ||
be ignored. | ||
|
||
If either `value` or `flags` is `nil` it will | ||
remain unchanged. If both are `nil`, key-value pair will be deleted. | ||
|
||
In case of mismatch, `false, false` will be returned. | ||
|
||
This method was first introduced in the `0.10.21` release. | ||
|
||
See also [ngx.shared.DICT](#ngxshareddict). | ||
|
||
[Back to TOC](#nginx-api-for-lua) | ||
|
||
ngx.shared.DICT.replace | ||
----------------------- | ||
|
||
|
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.
What does the "only returns if" part mean? If the if condition is not met, this method will never return? It cannot be. Maybe you mean "will only return the value and the flags" here? And you should also be explicit about what values it returns otherwise (like two nil values?)
The
cog
name is a bit confusing. How aboutget_if_not_eq
?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.
Yeah the "only returns if" part is not true.
Maybe something like:
I'm fine with
get_if_not_eq