Skip to content

Commit 9626013

Browse files
committed
feature: added the "exptime" argument to the pure C function of the
shdict:incr() API.
1 parent 01b3145 commit 9626013

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/ngx_http_lua_shdict.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -2623,11 +2623,12 @@ ngx_http_lua_ffi_shdict_get(ngx_shm_zone_t *zone, u_char *key,
26232623
int
26242624
ngx_http_lua_ffi_shdict_incr(ngx_shm_zone_t *zone, u_char *key,
26252625
size_t key_len, double *value, char **err, int has_init, double init,
2626-
int *forcible)
2626+
int exptime, int *forcible)
26272627
{
26282628
int i, n;
26292629
uint32_t hash;
26302630
ngx_int_t rc;
2631+
ngx_time_t *tp = NULL;
26312632
ngx_http_lua_shdict_ctx_t *ctx;
26322633
ngx_http_lua_shdict_node_t *sd;
26332634
double num;
@@ -2639,6 +2640,10 @@ ngx_http_lua_ffi_shdict_incr(ngx_shm_zone_t *zone, u_char *key,
26392640
return NGX_ERROR;
26402641
}
26412642

2643+
if (exptime > 0) {
2644+
tp = ngx_timeofday();
2645+
}
2646+
26422647
ctx = zone->data;
26432648

26442649
*forcible = 0;
@@ -2802,7 +2807,13 @@ ngx_http_lua_ffi_shdict_incr(ngx_shm_zone_t *zone, u_char *key,
28022807

28032808
sd->user_flags = 0;
28042809

2805-
sd->expires = 0;
2810+
if (exptime > 0) {
2811+
sd->expires = (uint64_t) tp->sec * 1000 + tp->msec
2812+
+ (uint64_t) exptime;
2813+
2814+
} else {
2815+
sd->expires = 0;
2816+
}
28062817

28072818
dd("setting value type to %d", LUA_TNUMBER);
28082819

0 commit comments

Comments
 (0)