hi ,
I want to get data from memcached , if the data is gzipped , I also need to gunzip it , I will check memcached flag to judge if it is gzipped . I use memc-nginx-module to get memcached data And I want to return value and flag , but ngx_location_capture only return value without flag . How can I get flag ? This is my nginx.conf . Thank you , very much
location ^~ /api/2/topic/nodejs {
set_md5 $md5_key $arg_client_id$arg_topicsid;
set $callback $arg_callback;
set $flag "1";
content_by_lua "
local args = ngx.req.get_uri_args();
local resp = ngx.location.capture( '/mem' , { share_all_vars = true });
if resp.status == 200 then
local encoding = ngx.var.flag;
if encoding == 2 then
local zlib = 'zlib';
local stream = zlib.inflate();
local jsonp = ngx.location.capture( '/mem2' , { args = args ,body = stream(resp.body) } );
ngx.say(jsonp.body);
else
local jsonp = ngx.location.capture('/mem2' , {args = args , body = resp.body});
ngx.say(jsonp.body);
end
elseif resp.status == 404 then
local resp2 = ngx.exec('@miss' , args);
end;
";
add_header lixin $flag;
}
location /mem2 {
set $callback $arg_callback;
content_by_lua "
ngx.req.read_body();
local req_body = ngx.req.get_body_data();
local req_result = ngx.var.callback .. '(' .. req_body .. ')';
ngx.say(req_result);
";
}
location /mem {
set $memc_cmd 'get';
set $memc_key '/topic/nodejs?$md5_key';
set $flag $memc_flags;
memc_pass memcached-cluster;
}