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
Retrieves the remaining TTL (time-to-live in seconds) of a key-value pair in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict). Returns the TTL as a number if the operation is successfully completed or `nil` and an error message otherwise.
6559
+
6560
+
If the key does not exist (or has already expired), this method will return `nil` and the error string `"not found"`.
6561
+
6562
+
The TTL is originally determined by the `exptime` argument of the [set](#ngxshareddictset), [add](#ngxshareddictadd), [replace](#ngxshareddictreplace) (and the likes) methods. It has a time resolution of `0.001` seconds. A value of `0` means that the item will never expire.
6563
+
6564
+
Example:
6565
+
6566
+
```lua
6567
+
6568
+
require"resty.core"
6569
+
6570
+
localcats=ngx.shared.cats
6571
+
localsucc, err=cats:set("Marry", "a nice cat", 0.5)
6572
+
6573
+
ngx.sleep(0.2)
6574
+
6575
+
localttl, err=cats:ttl("Marry")
6576
+
ngx.say(ttl) -- 0.3
6577
+
```
6578
+
6579
+
This feature was first introduced in the `v0.10.11` release.
6580
+
6581
+
**Note:** This method requires the `resty.core.shdict` or `resty.core` modules from the [lua-resty-core](https://github.com/openresty/lua-resty-core) library.
Updates the `exptime` (in second) of a key-value pair in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict). Returns a boolean indicating success if the operation completes or `nil` and an error message otherwise.
6596
+
6597
+
If the key does not exist, this method will return `nil` and the error string `"not found"`.
6598
+
6599
+
The `exptime` argument has a resolution of `0.001` seconds. If `exptime` is `0`, then the item will never expire.
6600
+
6601
+
Example:
6602
+
6603
+
```lua
6604
+
6605
+
require"resty.core"
6606
+
6607
+
localcats=ngx.shared.cats
6608
+
localsucc, err=cats:set("Marry", "a nice cat", 0.1)
6609
+
6610
+
succ, err=cats:expire("Marry", 0.5)
6611
+
6612
+
ngx.sleep(0.2)
6613
+
6614
+
localval, err=cats:get("Marry")
6615
+
ngx.say(val) -- "a nice cat"
6616
+
```
6617
+
6618
+
This feature was first introduced in the `v0.10.11` release.
6619
+
6620
+
**Note:** This method requires the `resty.core.shdict` or `resty.core` modules from the [lua-resty-core](https://github.com/openresty/lua-resty-core) library.
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
5502
+
5503
+
Retrieves the remaining TTL (time-to-live in seconds) of a key-value pair in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]]. Returns the TTL as a number if the operation is successfully completed or <code>nil</code> and an error message otherwise.
5504
+
5505
+
If the key does not exist (or has already expired), this method will return <code>nil</code> and the error string <code>"not found"</code>.
5506
+
5507
+
The TTL is originally determined by the <code>exptime</code> argument of the [[#ngx.shared.DICT.set|set]], [[#ngx.shared.DICT.add|add]], [[#ngx.shared.DICT.replace|replace]] (and the likes) methods. It has a time resolution of <code>0.001</code> seconds. A value of <code>0</code> means that the item will never expire.
5508
+
5509
+
Example:
5510
+
5511
+
<geshi lang="lua">
5512
+
require "resty.core"
5513
+
5514
+
local cats = ngx.shared.cats
5515
+
local succ, err = cats:set("Marry", "a nice cat", 0.5)
5516
+
5517
+
ngx.sleep(0.2)
5518
+
5519
+
local ttl, err = cats:ttl("Marry")
5520
+
ngx.say(ttl) -- 0.3
5521
+
</geshi>
5522
+
5523
+
This feature was first introduced in the <code>v0.10.11</code> release.
5524
+
5525
+
'''Note:''' This method 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.
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
5535
+
5536
+
Updates the <code>exptime</code> (in second) of a key-value pair in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]]. Returns a boolean indicating success if the operation completes or <code>nil</code> and an error message otherwise.
5537
+
5538
+
If the key does not exist, this method will return <code>nil</code> and the error string <code>"not found"</code>.
5539
+
5540
+
The <code>exptime</code> argument has a resolution of <code>0.001</code> seconds. If <code>exptime</code> is <code>0</code>, then the item will never expire.
5541
+
5542
+
Example:
5543
+
5544
+
<geshi lang="lua">
5545
+
require "resty.core"
5546
+
5547
+
local cats = ngx.shared.cats
5548
+
local succ, err = cats:set("Marry", "a nice cat", 0.1)
5549
+
5550
+
succ, err = cats:expire("Marry", 0.5)
5551
+
5552
+
ngx.sleep(0.2)
5553
+
5554
+
local val, err = cats:get("Marry")
5555
+
ngx.say(val) -- "a nice cat"
5556
+
</geshi>
5557
+
5558
+
This feature was first introduced in the <code>v0.10.11</code> release.
5559
+
5560
+
'''Note:''' This method 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.
0 commit comments