[php]代码库
local parser = require "redis.parser"
local reqs = {
{"set", "foo", "hello world"},
{"get", "foo"},
{"lpush","act1","{'user':1}"},
{"rpop","act1"}
}
local raw_reqs = {}
for i, req in ipairs(reqs) do
table.insert(raw_reqs, parser.build_query(req))
end
local res = ngx.location.capture("/redis?" .. #reqs,
{ body = table.concat(raw_reqs, "") })
if res.status ~= 200 or not res.body then
ngx.log(ngx.ERR, "failed to query redis")
ngx.say(ngx.ERR)
end
local replies = parser.parse_replies(res.body, #reqs)
for i, reply in ipairs(replies) do
ngx.say(reply[1])
end