Welcome! Log In Create A New Profile

Advanced

Re: lua parser and redis2 questions

agentzh
June 06, 2011 04:06AM
Halo!

Sorry for the delay! I've been on vocation again :P

I'd like to write some quick notes below regarding your code sample.

On Sun, Jun 5, 2011 at 2:15 AM, gregr401 <nginx-forum@nginx.us> wrote:
>
> location /mytest {
>                content_by_lua '
>                        local replies = ngx.location.capture("/redis2")
>                        local parser = require("redis.parser")
>                        -- assuming the replies variable holds n redis
> responses
>                        -- to be parsed:
>                        -- tried this in case n needed set:  local
> results = parser.parse_replies(replies, 2), same error
>                        local results = parser.parse_replies(replies,
> n)

Here, you assumed that ngx.location.capture() returns response body
directly, which is not the case. The ngx.location.capture() returns a
Lua table which has three slots, header, body, and status. See
ngx_lua's README for more details.

So here you should write

local res = ngx.location.capture("/redis2")
if res.status ~= ngx.HTTP_OK then
ngx.exit(res.status)
end

local results = parser.parse_replies(res.body, 2) -- 2 pipelined
requests in /redis2

> ## results in 500 and below error snippet
>
> I see the following in the error log:
>
>  [error] 4921#0: *3 lua handler aborted: runtime error: [string
> "content_by_lua"]:6: attempt to call field 'parse_replies' (a nil value)
> while sending to client  request: "GET /mytest HTTP/1.1"
>

This error implies that you're using a too old version of the
lua-redis-parser library which does not support the parse_replies
function at all. The latest tagged version of lua-redis-parser was
v0.04, which does not include the pipelining feature implemented in
master HEAD. I'm guessing you were using that.

I've just tagged master HEAD as the v0.05 release that you can download below:

https://github.com/agentzh/lua-redis-parser/downloads

>
> On a separate note, I've noticed when using Maxim's wonderful keepalive
> upstream module between redis, an established connection that performs a
> redis AUTH will actually maintain that 'authed' state for any subsequent
> redis calls (even those with no specific AUTH call).   I'd imagine these
> will work till the connections eventually timeout, keep this in mind
> when testing when using redis && auth.
>

Well, you cannot rely on that because you cannot really control how
and when the connection pool opens and closes connections.

For similar reasons, ngx_drizzle implements the charset option all by
itself on the C level by ensuring "set names 'some_charset'" was sent
to mysql exactly once for a connection. It does not use
ngx_http_upstream_keepalive, rather, its own connection pool
implementation, so it is possible.

Regards,
-agentzh

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

lua parser and redis2 questions

gregr401 June 01, 2011 07:27PM

Re: lua parser and redis2 questions

logar.damir June 04, 2011 08:49AM

Re: lua parser and redis2 questions

Marcos Ortiz June 04, 2011 11:12AM

Re: lua parser and redis2 questions

Marcos Ortiz June 04, 2011 11:16AM

Re: lua parser and redis2 questions

agentzh June 04, 2011 11:22AM

Re: lua parser and redis2 questions

gregr401 June 04, 2011 02:15PM

Re: lua parser and redis2 questions

agentzh June 06, 2011 04:06AM

Re: lua parser and redis2 questions

logar.damir June 04, 2011 04:26PM

Re: lua parser and redis2 questions

gregr401 June 05, 2011 06:40PM

Re: lua parser and redis2 questions

agentzh June 06, 2011 04:12AM

Re: lua parser and redis2 questions

logar.damir June 06, 2011 07:16AM

Re: lua parser and redis2 questions

agentzh June 06, 2011 10:56AM

Re: lua parser and redis2 questions

gregr401 June 06, 2011 12:50PM

Re: lua parser and redis2 questions

agentzh June 06, 2011 09:16PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 186
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