zoukankan      html  css  js  c++  java
  • drizzle lua 数据传递(ngx.location.capture)

    经常使用PHP开发的WEB开发人员,刚刚转到NGINX+DRIZZLE开发环境,开始估计会遇到LUA如何获取DRIZZLE+MYSQL返回数据的问题,下面给出我的一些经验。

    首先修改NGINX的配置文件

    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 返回的结果:[{"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}]

    然后在后面加入:

    location /lua{
        content_by_lua '
           local res = ngx.location.capture("/mysql")
           ngx.say("data: " .. res.body)
        ';  
    } 

    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}]

    最后大家也就都能猜到了

    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)

    搞定: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}]

  • 相关阅读:
    kernel 单独编译模块
    Python实现图的经典DFS、BFS、Dijkstra、Floyd、Prim、Kruskal算法
    Python实现BFS和DFS
    dpdk 20.02 igb_uio.ko 编译
    Kubernetes 文档
    controller-runtime/FAQ.md
    kubebuilder2.0学习笔记——进阶使用
    cloud-init 导致虚拟机启动太慢
    关闭 cloud-init 服务
    centos7 安装 docker calico
  • 原文地址:https://www.cnblogs.com/liqiu/p/2772529.html
Copyright © 2011-2022 走看看