test with openresty
Opened this issue · 0 comments
lloydzhou commented
test
docker run --rm --name redisab lloydzhou/redisab:latest
docker run --rm -it --link redisab:redisab -v `pwd`/test_nginx.conf:/etc/nginx/conf.d/default.conf -p 8000:80 openresty/openresty:1.19.9.1-alpine
curl http://localhost:8000/ab -d 'AB.TEST test1 LAYER layer1 WEIGHT 100 NAME testname1'
-->
0
curl http://localhost:8000/ab -d 'AB.TEST test1'
-->
["name","testname1","layer","layer1","weight","100","updated","1640241367767","type","number","default","0","created","1640241285694"]
test_nginx.conf
server {
listen 80;
server_name default_server;
location = /ab {
redis2_raw_query "$request_body\r\n";
redis2_pass redisab:6379;
body_filter_by_lua_block {
local chunk, eof = ngx.arg[1], ngx.arg[2]
local buffered = ngx.ctx.buffered
if not buffered then
buffered = {}
ngx.ctx.buffered = buffered
end
if chunk ~= "" then
buffered[#buffered + 1] = chunk
ngx.arg[1] = nil
end
if eof then
local parser = require "redis.parser"
local cjson = require "cjson"
local reply = table.concat(buffered)
ngx.ctx.buffered = nil
local res, typ = parser.parse_reply(reply)
ngx.arg[1] = cjson.encode(res)
end
}
}
}