From 944d4a127ba5a3701023671512ac31e95fd529ae Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Mon, 8 Jan 2018 15:11:32 -0800 Subject: [PATCH] feature: added the "exptime" argument to the pure C function of the shdict:incr() API. --- src/ngx_http_lua_shdict.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ngx_http_lua_shdict.c b/src/ngx_http_lua_shdict.c index 5b48eb4b0d..b300673e82 100644 --- a/src/ngx_http_lua_shdict.c +++ b/src/ngx_http_lua_shdict.c @@ -2623,11 +2623,12 @@ ngx_http_lua_ffi_shdict_get(ngx_shm_zone_t *zone, u_char *key, int ngx_http_lua_ffi_shdict_incr(ngx_shm_zone_t *zone, u_char *key, size_t key_len, double *value, char **err, int has_init, double init, - int *forcible) + long init_ttl, int *forcible) { int i, n; uint32_t hash; ngx_int_t rc; + ngx_time_t *tp = NULL; ngx_http_lua_shdict_ctx_t *ctx; ngx_http_lua_shdict_node_t *sd; double num; @@ -2639,6 +2640,10 @@ ngx_http_lua_ffi_shdict_incr(ngx_shm_zone_t *zone, u_char *key, return NGX_ERROR; } + if (init_ttl > 0) { + tp = ngx_timeofday(); + } + ctx = zone->data; *forcible = 0; @@ -2802,7 +2807,13 @@ ngx_http_lua_ffi_shdict_incr(ngx_shm_zone_t *zone, u_char *key, sd->user_flags = 0; - sd->expires = 0; + if (init_ttl > 0) { + sd->expires = (uint64_t) tp->sec * 1000 + tp->msec + + (uint64_t) init_ttl; + + } else { + sd->expires = 0; + } dd("setting value type to %d", LUA_TNUMBER);