1

I am using a lua script to push paramters into redis from a nginx http server https://github.com/openresty/lua-resty-redis

I do not want to make a new connection to redis server everytime. Can I persist the redis connection. Also is there an option to make this async

2
  • You can set keep alive connections between nginx and redis, check this github.com/openresty/lua-resty-redis#set_keepalive Commented May 31, 2016 at 14:38
  • Ok if I set the keepalive how do I reuse the existing connection from the redis pool Commented May 31, 2016 at 18:58

1 Answer 1

3

If you use set_keepalive specifying the connection pool size (2nd paramater), when you connect, the lua-resty-redis library will automatically try to resolve a previous idle connection if any. It also allows to specify a custom name for your pool. It is all decribed in 'redis#connect' method documentation:

Before actually resolving the host name and connecting to the remote backend, this method will always look up the connection pool for matched idle connections created by previous calls of this method.

An optional Lua table can be specified as the last argument to this method to specify various connect options:

  • pool

Specifies a custom name for the connection pool being used. If omitted, then the connection pool name will be generated from the string template <host>:<port> or <unix-socket-path>.

As for the "async" requirement, the library is already 100% nonblocking.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.