使用 nginx 的 lua 脚本中的持久性 redis 句柄

Persistent redis handle in a lua script with nginx

我正在使用 lua 脚本将参数从 nginx http 服务器推送到 redis https://github.com/openresty/lua-resty-redis

我不想每次都与redis 服务器建立新连接。我可以坚持redis连接吗?还有一个选项可以使这个异步

如果您使用set_keepalive specifying the connection pool size (2nd paramater), when you connect,lua-resty-redis 库将自动尝试解析之前的空闲连接(如果有)。 它还允许为您的池指定自定义名称。全部在'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>.

至于“异步”需求,库已经100% nonblocking