Reputation: 1193
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
Upvotes: 1
Views: 2740
Reputation: 1672
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.
Upvotes: 3