Drizzlelua data transmission (ngx. location. capture) _ MySQL

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.