Last active
October 2, 2015 18:04
-
-
Save Ryan4CN/d9e5a8b4401c1bfeafdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- nginx lua 模块缓存 | |
cjson = require "cjson" | |
redis = require "resty.redis" | |
if ngx.req.get_headers()['PARAMS'] == nil then | |
ngx.say('params error') | |
return | |
end | |
j=cjson.new().decode(ngx.req.get_headers()["PARAMS"]) | |
red = redis:new() | |
red:set_timeout(1000) | |
ok, err = red:connect("127.0.0.1", 6379) | |
if not ok then | |
ngx.log("LUA REDIS: ", err) | |
return | |
end | |
akey = j.channel..j.version_code | |
res, err = red:get(akey) | |
if not res or res == ngx.null then | |
lres = ngx.location.capture("/real/api/base") | |
res = lres.body | |
red:set(akey, res) | |
red:expire(akey, 360) | |
end | |
ngx.say(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment