Drizzlelua data transmission (ngx. location. capture) bitsCN.com
WEB developers who often use PHP development have just switched to the NGINX + DRIZZLE development environment and started to estimate how LUA can obtain the data returned by DRIZZLE + MYSQL. The following are some of my experiences.
First, modify the NGINX configuration file.
Location/mysql {
Set $ name $1;
Set_quote_ SQL _str $ quote_name $ name;
Set $ SQL "SELECT * FROM crawl WHERE id = 3 ";
Drizzle_query $ SQL; drizzle_pass mysql; rds_json on;
}
Curl localhost: 8080/mysql returned results: [{"id": 3, "url_id": "100", "url_type": "item", "date ": "0000-00-00", "url": "http://item.taobao.com/item.htm? Id = 100 "," status ": 0," failures ": 0," start_date ": 0," unit_id ": 54848}]
Then add the following content:
location /lua{ content_by_lua ' local res = ngx.location.capture("/mysql") ngx.say("data: " .. res.body) '; }
Result returned by curl localhost: 8080/lua: data: [{"id": 3, "url_id": "100", "url_type": "item", "date ": "0000-00-00", "url": "http://item.taobao.com/item.htm? Id = 100 "," status ": 0," failures ": 0," start_date ": 0," unit_id ": 54848}]
Finally, you can guess it.
location /luafile { content_by_lua_file /usr/local/openresty/nginx/html/test.lua; }
Test. lua
local res = ngx.location.capture("/mysql")ngx.say("data: " .. res.body)
Result returned by curl localhost: 8080/luafile: data: [{"id": 3, "url_id": "100", "url_type": "item ", "date": "0000-00-00", "url": "http://item.taobao.com/item.htm? Id = 100 "," status ": 0," failures ": 0," start_date ": 0," unit_id ": 54848}]
BitsCN.com