ngx_lua将lua嵌入到nginx,让nginx执行lua脚本,高并发,非阻塞的处理各种请求。
url请求nginx服务器,然后lua查询redis,返回json数据。
参见《LNMLGC》架构
二.安装redis2-nginx-module模块
get https://github.com/openresty/echo-nginx-module...
http {
...
upstream redis_pool {
server localhost:6379;
keepalive 1024 single;
//定义连接池大小,当连接数达到此数后,后续的连接为短连接
}
server {
...
location /get_redis{
#internal;
set_unescape_uri $key $arg_key;
redis2_query hgetall $key;
redis2_pass redis_pool;
}
location /json {
content_by_lua_file conf/test.lua;
}
}
}local json = require("json")
local parser = require("redis.parser")
local res = ngx.location.capture("/get_redis",{
args = { key = ngx.var.arg_key }
})
if res.status == 200 then
reply = parser.parse_reply(res.body)
value = json.encode(reply)
ngx.say(value)
a = json.decode(value)
ngx.say(a[2])
end["www","www.ttlsa.com","mail","mail.ttlsa.com"]
www.ttlsa.com
nginx+lua+redis构建高并发应用,布布扣,bubuko.com
原文:http://blog.csdn.net/jiao_fuyou/article/details/36186485