<div><br>Thank you very much, agentzh!</div>
<div>I'll immediately try the <font color="#0000ff">xss-nginx-module </font><font color="#000000">module in your guide.<br></font></div>
<div> </div>
<div> </div>
<div><br> </div>
<div class="gmail_quote">2012/6/16 agentzh <span dir="ltr"><<a href="mailto:agentzh@gmail.com" target="_blank">agentzh@gmail.com</a>></span><br>
<blockquote style="BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex" class="gmail_quote">Hello!<br>
<div class="im"><br>On Sat, Jun 16, 2012 at 10:08 AM, agentzh <<a href="mailto:agentzh@gmail.com">agentzh@gmail.com</a>> wrote:<br></div>Sorry, I was reading too fast. For the memcached commands other than<br>"get", ngx_memc will return the raw memcached responses, and in your<br>
case, for the "incr" command, the response is ended by a CR LF<br>sequence.<br><br>If it bothers you, then you're recommended to use ngx_lua with<br>lua-resty-memcached instead, for example:<br><br> # the following line is not required if the ngx_openresty bundle is used.<br>
lua_package_path "/path/to/lua-resty-memcached/lib/?.lua;;";<br><br> server {<br> listen 8080;<br>
<div class="im"><br> location ~ "^/property/([0-9]+)" {<br> charset utf-8;<br></div> default_type 'application/json';<br><br> xss_callback_arg callback;<br> xss_get on;<br><br>
content_by_lua '<br> local memcached = require "resty.memcached"<br> local memc = memcached:new()<br><br> memc:set_timeout(500) -- 500 ms<br><br> local ok, err = memc:connect("127.0.0.1", 11211)<br>
if not ok then<br> ngx.log(ngx.ERR, "failed to connect to memcached: ", err)<br> return ngx.exit(500)<br> end<br><br> local key = "property_" .. ngx.var[1]<br>
local newval, err = memc:incr(key, 1)<br> if not newval then<br> ngx.log(ngx.ERR, "failed to incr the key in memcached: ", err)<br> return ngx.exit(500)<br> end<br>
<br> -- the connection pool capacity is set to 1024 connections<br> memc:set_keepalive(0, 1024)<br><br> ngx.print([[{"]], key, [[":"]], newval, [["}]])<br> ';<br>
}<br> }<br><br>The example above utilizes the following components:<br><br> <a href="http://wiki.nginx.org/HttpLuaModule" target="_blank">http://wiki.nginx.org/HttpLuaModule</a><br> <a href="https://github.com/agentzh/lua-resty-memcached" target="_blank">https://github.com/agentzh/lua-resty-memcached</a><br>
<a href="https://github.com/agentzh/xss-nginx-module" target="_blank">https://github.com/agentzh/xss-nginx-module</a><br><br>If you're too lazy to download and install all these dependencies, you<br>can try out the ngx_openresty bundle instead:<br>
<br> <a href="http://openresty.org/#Download" target="_blank">http://openresty.org/#Download</a><br><br>Best regards,<br>-agentzh<br></blockquote></div><br>