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
Copy file name to clipboardExpand all lines: README.markdown
+91-8Lines changed: 91 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,7 @@ Production ready.
62
62
Version
63
63
=======
64
64
65
-
This document describes ngx_lua [v0.10.8](https://github.com/openresty/lua-nginx-module/tags) released on 8 April 2017.
65
+
This document describes ngx_lua [v0.10.10](https://github.com/openresty/lua-nginx-module/tags) released on 8 August 2017.
66
66
67
67
Synopsis
68
68
========
@@ -990,7 +990,7 @@ Copyright and License
990
990
991
991
This module is licensed under the BSD license.
992
992
993
-
Copyright (C) 2009-2016, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
993
+
Copyright (C) 2009-2017, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
994
994
995
995
Copyright (C) 2009-2017, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>, OpenResty Inc.
996
996
@@ -1335,16 +1335,19 @@ Runs the Lua code specified by the argument `<lua-script-str>` on the global Lua
1335
1335
1336
1336
When Nginx receives the `HUP` signal and starts reloading the config file, the Lua VM will also be re-created and `init_by_lua` will run again on the new Lua VM. In case that the [lua_code_cache](#lua_code_cache) directive is turned off (default on), the `init_by_lua` handler will run upon every request because in this special mode a standalone Lua VM is always created for each request.
1337
1337
1338
-
Usually you can register (true) Lua global variables or pre-load Lua modules at server start-up by means of this hook. Here is an example for pre-loading Lua modules:
1338
+
Usually you can pre-load Lua modules at server start-up by means of this hook and take advantage of modern operating systems' copy-on-write (COW) optimization. Here is an example for pre-loading Lua modules:
1339
1339
1340
1340
```nginx
1341
1341
1342
-
init_by_lua 'cjson = require "cjson"';
1342
+
# this runs before forking out nginx worker processes:
1343
+
init_by_lua_block { require "cjson" }
1343
1344
1344
1345
server {
1345
1346
location = /api {
1346
1347
content_by_lua_block {
1347
-
ngx.say(cjson.encode({dog = 5, cat = 6}))
1348
+
-- the following require() will just return
1349
+
-- the alrady loaded module from package.loaded:
1350
+
ngx.say(require "cjson".encode{dog = 5, cat = 6})
1348
1351
}
1349
1352
}
1350
1353
}
@@ -1356,10 +1359,10 @@ You can also initialize the [lua_shared_dict](#lua_shared_dict) shm storage at t
Equivalent to [ssl_session_store_by_lua_block](#ssl_session_store_by_lua_block), except that the file specified by `<path-to-lua-script-file>` contains the Lua code, or rather, the [Lua/LuaJIT bytecode](#lualuajit-bytecode-support) to be executed.
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.
Copy file name to clipboardExpand all lines: doc/HttpLuaModule.wiki
+81-8Lines changed: 81 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Production ready.
10
10
11
11
= Version =
12
12
13
-
This document describes ngx_lua [https://github.com/openresty/lua-nginx-module/tags v0.10.8] released on 8 April 2017.
13
+
This document describes ngx_lua [https://github.com/openresty/lua-nginx-module/tags v0.10.10] released on 8 August 2017.
14
14
15
15
= Synopsis =
16
16
<geshi lang="nginx">
@@ -812,7 +812,7 @@ There are also various testing modes based on mockeagain, valgrind, and etc. Ref
812
812
813
813
This module is licensed under the BSD license.
814
814
815
-
Copyright (C) 2009-2016, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
815
+
Copyright (C) 2009-2017, by Xiaozhe Wang (chaoslawful) <chaoslawful@gmail.com>.
816
816
817
817
Copyright (C) 2009-2017, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>, OpenResty Inc.
818
818
@@ -1057,15 +1057,18 @@ Runs the Lua code specified by the argument <code><lua-script-str></code> on the
1057
1057
1058
1058
When Nginx receives the <code>HUP</code> signal and starts reloading the config file, the Lua VM will also be re-created and <code>init_by_lua</code> will run again on the new Lua VM. In case that the [[#lua_code_cache|lua_code_cache]] directive is turned off (default on), the <code>init_by_lua</code> handler will run upon every request because in this special mode a standalone Lua VM is always created for each request.
1059
1059
1060
-
Usually you can register (true) Lua global variables or pre-load Lua modules at server start-up by means of this hook. Here is an example for pre-loading Lua modules:
1060
+
Usually you can pre-load Lua modules at server start-up by means of this hook and take advantage of modern operating systems' copy-on-write (COW) optimization. Here is an example for pre-loading Lua modules:
1061
1061
1062
1062
<geshi lang="nginx">
1063
-
init_by_lua 'cjson = require "cjson"';
1063
+
# this runs before forking out nginx worker processes:
1064
+
init_by_lua_block { require "cjson" }
1064
1065
1065
1066
server {
1066
1067
location = /api {
1067
1068
content_by_lua_block {
1068
-
ngx.say(cjson.encode({dog = 5, cat = 6}))
1069
+
-- the following require() will just return
1070
+
-- the alrady loaded module from package.loaded:
1071
+
ngx.say(require "cjson".encode{dog = 5, cat = 6})
1069
1072
}
1070
1073
}
1071
1074
}
@@ -1076,10 +1079,10 @@ You can also initialize the [[#lua_shared_dict|lua_shared_dict]] shm storage at
1076
1079
<geshi lang="nginx">
1077
1080
lua_shared_dict dogs 1m;
1078
1081
1079
-
init_by_lua '
1082
+
init_by_lua_block {
1080
1083
local dogs = ngx.shared.dogs;
1081
1084
dogs:set("Tom", 56)
1082
-
';
1085
+
}
1083
1086
1084
1087
server {
1085
1088
location = /api {
@@ -2368,7 +2371,7 @@ Note that: this directive is only allowed to used in '''http context''' from the
2368
2371
2369
2372
'''context:''' ''http''
2370
2373
2371
-
'''phase:''' ''right-before-SSL-handshake''
2374
+
'''phase:''' ''right-after-SSL-handshake''
2372
2375
2373
2376
Equivalent to [[#ssl_session_store_by_lua_block|ssl_session_store_by_lua_block]], except that the file specified by <code><path-to-lua-script-file></code> contains the Lua code, or rather, the [[#Lua/LuaJIT bytecode support|Lua/LuaJIT bytecode]] to be executed.
2374
2377
@@ -5309,6 +5312,8 @@ The resulting object <code>dict</code> has the following methods:
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
5618
+
5619
+
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.
5620
+
5621
+
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>.
5622
+
5623
+
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.
5624
+
5625
+
Example:
5626
+
5627
+
<geshi lang="lua">
5628
+
require "resty.core"
5629
+
5630
+
local cats = ngx.shared.cats
5631
+
local succ, err = cats:set("Marry", "a nice cat", 0.5)
5632
+
5633
+
ngx.sleep(0.2)
5634
+
5635
+
local ttl, err = cats:ttl("Marry")
5636
+
ngx.say(ttl) -- 0.3
5637
+
</geshi>
5638
+
5639
+
This feature was first introduced in the <code>v0.10.11</code> release.
5640
+
5641
+
'''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>
5651
+
5652
+
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.
5653
+
5654
+
If the key does not exist, this method will return <code>nil</code> and the error string <code>"not found"</code>.
5655
+
5656
+
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.
5657
+
5658
+
Example:
5659
+
5660
+
<geshi lang="lua">
5661
+
require "resty.core"
5662
+
5663
+
local cats = ngx.shared.cats
5664
+
local succ, err = cats:set("Marry", "a nice cat", 0.1)
5665
+
5666
+
succ, err = cats:expire("Marry", 0.5)
5667
+
5668
+
ngx.sleep(0.2)
5669
+
5670
+
local val, err = cats:get("Marry")
5671
+
ngx.say(val) -- "a nice cat"
5672
+
</geshi>
5673
+
5674
+
This feature was first introduced in the <code>v0.10.11</code> release.
5675
+
5676
+
'''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