The resty.redis object instance cannot be stored in a Lua variable at the Lua module level, because it will then be shared by all the concurrent requests handled by the same nginx worker process (see https://github.com/openresty/lua-nginx-module/#data-sharing-within-an-nginx-worker ) and result in bad race conditions when concurrent requests are trying to use the same resty.redis instance (you would see the "bad request" or "socket busy" error to be returned from the method calls). You should always initiate resty.redis objects in function local variables or in the ngx.ctx table. These places all have their own data copies for each request.
But here, we are still using resty.redis instance as a Lua variable at Lua module level. Isn't that a problem?
@steve0511 Referring to the limitations mentioned by openresty/lua-resty-redis
But here, we are still using
resty.redis
instance as a Lua variable at Lua module level. Isn't that a problem?