Hello!
On Sun, Nov 1, 2015 at 2:48 AM, RJoshi wrote:
> I am using redis as a second level cache for my application but under load,
> getting error Can't assign requested address. It seems connection pool is
> not getting utilized.
>
> This module is access from access_by_lua_file file. I also tried copying
> code from init_redis() function into get() and set() functions but did not
> help.
set_keepalive() is not setting an attribute of a connection, rather,
it's an action by putting the current connection into the pool for
reuse (thus, the current Lua object can no longer be used without
connect() calls). Please read the documentation for set_keepalive()
more closely. So you should not call set_keepalive() right after
new(), because that does not make sense and always fails.
Also, set_keepalive() can fail. Please always check its return values
to handle errors (if any). In case of failures, the error string
returned as the 2nd value can give details.
In addition, avoid your Lua global variable "red" in your module code
since cosocket objects must be per-request (you can pass it around
either by your own function call arguments or via the ngx.ctx magical
table, the former is much more efficient though).
BTW, connection pools are per-worker, it does not make sense to use a
too large value for the pool size if you already have quite a few
workers running.
Finally, the get_reused_times() method can be used to verify if the
connection obtained by connect() is reused from the pool or newly
established.
Regards,
-agentzh