8000 Merge branch 'master' of https://github.com/Tinywan/Lua-Nginx-Redis · Tinywan/lua-nginx-redis@967277f · GitHub
[go: up one dir, main page]

Skip to content

Commit 967277f

Browse files
committed
2 parents d90e862 + d0caac1 commit 967277f

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

Openresty/Lua-file/lua-01.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
--]]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
--]]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* [Lua脚本运行Redis](#line)
4343

4444
* [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)
4646
* 单行文本1
4747

4848
* [链接](#link)

0 commit comments

Comments
 (0
0