Skip to content

Add support for shdict_get flag comparison #1922

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ install:
- git clone https://github.com/openresty/rds-json-nginx-module.git ../rds-json-nginx-module
- git clone https://github.com/openresty/srcache-nginx-module.git ../srcache-nginx-module
- git clone https://github.com/openresty/redis2-nginx-module.git ../redis2-nginx-module
- git clone https://github.com/openresty/lua-resty-core.git ../lua-resty-core
- git clone https://github.com/webcore-no/lua-resty-core.git ../lua-resty-core
- git clone https://github.com/openresty/lua-resty-lrucache.git ../lua-resty-lrucache
- git clone https://github.com/openresty/lua-resty-mysql.git ../lua-resty-mysql
- git clone https://github.com/openresty/lua-resty-string.git ../lua-resty-string
- git clone https://github.com/openresty/stream-lua-nginx-module.git ../stream-lua-nginx-module
- git clone https://github.com/webcore-no/stream-lua-nginx-module.git ../stream-lua-nginx-module
- git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git luajit2

before_script:
Expand Down
7 changes: 5 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6827,12 +6827,15 @@ This feature was first introduced in the `v0.3.1rc22` release.
ngx.shared.DICT.get
-------------------

**syntax:** *value, flags = ngx.shared.DICT:get(key)*
**syntax:** *value, flags, flags_match = ngx.shared.DICT:get(key, 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**

Retrieving the value in the dictionary [ngx.shared.DICT](#ngxshareddict) for the key `key`. If the key does not exist or has expired, then `nil` will be returned.

If flags is not `nil`, value will only be returned if flags do not match with shm.
A 3rd return argument will indicate if flags matched.

In case of errors, `nil` and a string describing the error will be returned.

The value returned will have the original data type when they were inserted into the dictionary, for example, Lua booleans, numbers, or strings.
Expand Down Expand Up @@ -6866,7 +6869,7 @@ See also [ngx.shared.DICT](#ngxshareddict).
ngx.shared.DICT.get_stale
-------------------------

**syntax:** *value, flags, stale = ngx.shared.DICT:get_stale(key)*
**syntax:** *value, flags, stale, flags_match = ngx.shared.DICT:get_stale(key, 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**

Expand Down
7 changes: 5 additions & 2 deletions doc/HttpLuaModule.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -5778,12 +5778,15 @@ This feature was first introduced in the <code>v0.3.1rc22</code> release.

== ngx.shared.DICT.get ==

'''syntax:''' ''value, flags = ngx.shared.DICT:get(key)''
'''syntax:''' ''value, flags, flags_match = ngx.shared.DICT:get(key, 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*''

Retrieving the value in the dictionary [[#ngx.shared.DICT|ngx.shared.DICT]] for the key <code>key</code>. If the key does not exist or has expired, then <code>nil</code> will be returned.

If flags is not <code>nil</code>, value will only be returned if flags do not match with shm.
A 3rd return argument will indicate if flags matched.

In case of errors, <code>nil</code> and a string describing the error will be returned.

The value returned will have the original data type when they were inserted into the dictionary, for example, Lua booleans, numbers, or strings.
Expand Down Expand Up @@ -5812,7 +5815,7 @@ See also [[#ngx.shared.DICT|ngx.shared.DICT]].

== ngx.shared.DICT.get_stale ==

'''syntax:''' ''value, flags, stale = ngx.shared.DICT:get_stale(key)''
'''syntax:''' ''value, flags, stale, flags_match = ngx.shared.DICT:get_stale(key, 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*''

Expand Down
10 changes: 9 additions & 1 deletion src/ngx_http_lua_shdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ int
ngx_http_lua_ffi_shdict_get(ngx_shm_zone_t *zone, u_char *key,
size_t key_len, int *value_type, u_char **str_value_buf,
size_t *str_value_len, double *num_value, int *user_flags,
int get_stale, int *is_stale, char **err)
int *user_flags_neq, int get_stale, int *is_stale, char **err)
{
ngx_str_t name;
uint32_t hash;
Expand Down Expand Up @@ -1613,6 +1613,14 @@ ngx_http_lua_ffi_shdict_get(ngx_shm_zone_t *zone, u_char *key,
return NGX_OK;
}

if (*user_flags_neq && *user_flags == (int) sd->user_flags) {
*is_stale = (rc == NGX_DONE);
*user_flags_neq = 0;
ngx_shmtx_unlock(&ctx->shpool->mutex);
*value_type = LUA_TNIL;
return NGX_OK;
}

/* rc == NGX_OK || (rc == NGX_DONE && get_stale) */

*value_type = sd->value_type;
Expand Down
Loading