redis2_query hgetall $key;
redis2_pass redis_pool;
}
location /json {
content_by_lua_file conf/test_redis.lua;
}
}
}
三、测试
1、编写脚本
编写上面配置中的test_redis.lua脚本
#vi test_redis.lua
local json = require("json")
local parser = require("redis.parser")
local res = ngx.location.capture("/get_redis",{args = { key = ngx.var.arg_key }})
if res.status == 200 then
reply = parser.parse_reply(res.body)
value = json.encode(reply)
ngx.say(value)
a = json.decode(value)
ngx.say(a[2])
end
2、构造数据
#redis-cli -h 192.168.1.105 -p 6379
redis 192.168.1.105:6379>HMSET testnlr www www.joyvc.cn mail mail.joyvc.cn
3、开始测试
#curl 'http://192.168.1.104/json?key=testnlr'
["www", "www.joyvc.cn", "mail", "mail.joyvc.cn"]








