Hello!
On Sun, Oct 13, 2013 at 8:54 AM, Ron Schwartz wrote:
> reads_lua:
>
[...]
>
> local redis = require "resty.redis" -#is it ok to initialize the connection
> here?
Calling require() just introduces a Lua module (just like "#include"
in C, "use" in Perl, and "import" in Java). You're not initializing
the connection here. The connect() call initiates a new connection (or
obtaining one from the connection pool if any).
> local red = redis:new()
> red:set_timeout(1000) -- 1 sec
> red:connect("127.0.0.1", 6379)
>
You should check the return values of connect() here and handle the
errors if there're any. Because connecting to the redis *could* fail.
> local ok, err = red:evalsha(ngx.var.redis_reads_hash, 1, "args", args_json)
>
Same here. You should check the "ok" value and handle the error
specified in "err" if "ok" is nil or false.
> if ok then red:set_keepalive(10000, 100) end
>
Same here. set_keepalive also returns the result of the operation.
> I did a test load with apache bench - ab -n6000 -c 300
> "http://<counting_server_path>/reads?post_id=1111" and i received some
> "attempt to send data on a closed socket" in the error log. Any idea what am
> i doing wrong?
>
When there is fatal error happens in any of your redis operations
(like connect, evalsha, and set_keepalive), the redis object and its
socket object will automatically get closed. Any subsequent operations
will yield such error messages. So this error message is not the cause
but the consequence of earlier errors and the lack of proper error
handling in your Lua code. Find out the first error messages in your
error.log file.
If you do look at the sample code in lua-resty-redis's documentation,
you should see error handling code there.
>
> I hope you can help me with this. There is no much of documentation around.
>
I suggest you google for the error message with the "lua-resty-redis"
keyword the next time you have a problem.
I'm cc'ing the openresty-en mailing list:
https://groups.google.com/group/openresty-en Please join the
openresty-en mailing list and post such questions there if you fail to
find an answer on Google the next time. That way, other people having
similar problems can find our discussions on Google as well ;)
Regards,
-agentzh