首页 > 其他 > 详细

Nginx + Lua + 共享内存

时间:2015-03-16 19:10:07      阅读:862      评论:0      收藏:0      [点我收藏+]

转自:http://blog.csdn.net/lxb_champagne/article/details/17099383

    lua_package_path "/usr/local/share/luajit-2.0.2/jit?.lua;;";
    lua_shared_dict devicedb 45m; 
        location /query {
           default_type text/plain;
           content_by_lua                     local args = ngx.req.get_uri_args()
                    local devicetype = args["device"]
                    local devicedb = ngx.shared.devicedb
                    local res = devicedb:get(devicetype)

                    ngx.say(res)
               ;
        }

        location /update {
            default_type text/plain;
            content_by_lua                     local devicedb = ngx.shared.devicedb

                    for item in io.lines("/usr/local/nginx-1.4.2/data/rule.txt") do
                        _,_,device_type, device_rule = string.find(item, "^(%a+)--(%a+)$")
                        devicedb:set(device_type,device_rule)
                    end

                    ngx.say("ok")            
               ;
        }

rule.txt文件格式

SAMSUNG--samRule
APPLE--appRule
XIAOMI--xiaRule

 

Nginx + Lua + 共享内存

原文:http://www.cnblogs.com/wangxusummer/p/4342401.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!