Welcome! Log In Create A New Profile

Advanced

Re: an unexpected newline appears when use memc and echo_location_async, how to delete the newline ?

Xiangong Yang
June 15, 2012 11:38PM
Thank you very much, agentzh!
I'll immediately try the xss-nginx-module module in your guide.




2012/6/16 agentzh <agentzh@gmail.com>

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

an unexpected newline appears when use memc and echo_location_async, how to delete the newline ?

Xiangong Yang June 15, 2012 09:52AM

Re: an unexpected newline appears when use memc and echo_location_async, how to delete the newline ?

Xiangong Yang June 15, 2012 11:38PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 159
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready