Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Original file line number Diff line number Diff line change
1
+ -- lua-01.lua
2
+ local _M = {}
3
+ local data = {dog = 3 ,cat = 4 ,pig = 5 ,}
4
+ function _M .get_age (name )
5
+ return data [name ]
6
+ end
7
+ return _M
8
+
9
+ --[[
10
+ location /lua_file {
11
+ default_type 'text/html'; -- 设置该行,则在浏览器就可以访问了
12
+ lua_code_cache off; -- 关闭缓存
13
+ content_by_lua_block {
14
+ local mydata = require "../Lua/lua-01" -- 注意这个路径 conf/nginx.conf 为相对路径的
15
+ ngx.say(mydata.get_age("dog"))
16
+ }
17
+ }
18
+ --]]
Original file line number Diff line number Diff line change
1
+ location / other {
2
+ content_by_lua_block {
3
+ ngx .say (" dog = " , ngx .var .dog )
4
+ ngx .say (" cat = " , ngx .var .cat )
5
+ ngx .say (" name = " ,ngx .var .name )
6
+ }
7
+ }
8
+
9
+ location / lua123 {
10
+ set $dog ' ' ;
11
+ set $cat ' ' ;
12
+ set $name ' ' ; # -- 下面要传递的参数必须的在这里提前声明设置了,否则会报错 500
13
+ content_by_lua_block {
14
+ res = ngx .location .capture (" /other" ,
15
+ { vars = { dog = " hello" , cat = 32 ,name = ' tinywan' }});
16
+ ngx .print (res .body )
17
+ }
18
+ }
19
+
20
+ --[[
21
+ 下面是错误的做法!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22
+ location /other {
23
+ content_by_lua_block {
24
+ ngx.say("dog = ", ngx.var.dog)
25
+ ngx.say("cat = ", ngx.var.cat)
26
+ ngx.say("name = ",ngx.var.name)
27
+ }
28
+ }
29
+
30
+ location /lua123 {
31
+ set $dog '';
32
+ set $cat '';
33
+ content_by_lua_block {
34
+ res = ngx.location.capture("/other",
35
+ { vars = { dog = "hello", cat = 32,name = 'tinywan' }});
36
+ ngx.print(res.body)
37
+ }
38
+ }
39
+ --]]
Original file line number Diff line number Diff line change 42
42
* [ Lua脚本运行Redis] ( #line )
43
43
44
44
* [ PHP脚本运行Redis] ( #line )
45
- * PHP 脚本执行一个Redis 订阅功能,用于监听键过期事件,返回一个回调,API接受改事件
45
+ * [ PHP 脚本执行一个Redis 订阅功能,用于监听键过期事件,返回一个回调,API接受改事件] ( https://github.com/Tinywan/Lua-Nginx-Redis/blob/master/Redis-PHP/Php-Run-Redis-psubscribe/nohupRedisNotify.php )
46
46
* 单行文本1
47
47
48
48
* [ 链接] ( #link )
You can’t perform that action at this time.
0 commit comments