You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**optional requirement:**`resty.core.shdict` or `resty.core`
6459
+
6458
6460
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.
6459
6461
6460
6462
When the key does not exist or has already expired in the shared dictionary,
@@ -6464,6 +6466,25 @@ When the key does not exist or has already expired in the shared dictionary,
6464
6466
6465
6467
Like the [add](#ngxshareddictadd) method, it also overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone.
6466
6468
6469
+
The optional `init_ttl` argument specifies expiration time (in seconds) of the value when it is initialized via the `init` argument. The time resolution is `0.001` seconds. If `init_ttl` takes the value `0` (which is the default), then the item will never expire. This argument cannot be provided without providing the `init` argument as well, and has no effect if the value already exists (e.g., if it was previously inserted via [set](#ngxshareddictset) or the likes).
6470
+
6471
+
**Note:** Usage of the `init_ttl` argument requires the `resty.core.shdict` or `resty.core` modules from the [lua-resty-core](https://github.com/openresty/lua-resty-core) library. Example:
The `forcible` return value will always be `nil` when the `init` argument is not specified.
6468
6489
6469
6490
If this method succeeds in storing the current item by forcibly removing other not-yet-expired items in the dictionary via LRU, the `forcible` return value will be `true`. If it stores the item without forcibly removing other valid items, then the return value `forcible` will be `false`.
@@ -6476,6 +6497,8 @@ This method was first introduced in the `v0.3.1rc22` release.
6476
6497
6477
6498
The optional `init` parameter was first added in the `v0.10.6` release.
6478
6499
6500
+
The optional `init_ttl` parameter was introduced in the `v0.10.12rc2` release.
'''optional requirement:''' <code>resty.core.shdict</code> or <code>resty.core</code>
5420
+
5419
5421
Increments the (numerical) value for <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]] by the step value <code>value</code>. Returns the new resulting number if the operation is successfully completed or <code>nil</code> and an error message otherwise.
5420
5422
5421
5423
When the key does not exist or has already expired in the shared dictionary,
@@ -5425,6 +5427,24 @@ When the key does not exist or has already expired in the shared dictionary,
5425
5427
5426
5428
Like the [[#ngx.shared.DICT.add|add]] method, it also overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone.
5427
5429
5430
+
The optional <code>init_ttl</code> argument specifies expiration time (in seconds) of the value when it is initialized via the <code>init</code> argument. The time resolution is <code>0.001</code> seconds. If <code>init_ttl</code> takes the value <code>0</code> (which is the default), then the item will never expire. This argument cannot be provided without providing the <code>init</code> argument as well, and has no effect if the value already exists (e.g., if it was previously inserted via [[#ngx.shared.DICT.set|set]] or the likes).
5431
+
5432
+
'''Note:''' Usage of the <code>init_ttl</code> argument requires the <code>resty.core.shdict</code> or <code>resty.core</code> modules from the [https://github.com/openresty/lua-resty-core lua-resty-core] library. Example:
5433
+
5434
+
<geshi lang="lua">
5435
+
require "resty.core"
5436
+
5437
+
local cats = ngx.shared.cats
5438
+
local newval, err = cats:incr("black_cats", 1, 0, 0.1)
5439
+
5440
+
print(newval) -- 1
5441
+
5442
+
ngx.sleep(0.2)
5443
+
5444
+
local val, err = cats:get("black_cats")
5445
+
print(val) -- nil
5446
+
</geshi>
5447
+
5428
5448
The <code>forcible</code> return value will always be <code>nil</code> when the <code>init</code> argument is not specified.
5429
5449
5430
5450
If this method succeeds in storing the current item by forcibly removing other not-yet-expired items in the dictionary via LRU, the <code>forcible</code> return value will be <code>true</code>. If it stores the item without forcibly removing other valid items, then the return value <code>forcible</code> will be <code>false</code>.
@@ -5437,6 +5457,8 @@ This method was first introduced in the <code>v0.3.1rc22</code> release.
5437
5457
5438
5458
The optional <code>init</code> parameter was first added in the <code>v0.10.6</code> release.
5439
5459
5460
+
The optional <code>init_ttl</code> parameter was introduced in the <code>v0.10.12rc2</code> release.
0 commit comments