steve0511 / resty-redis-cluster

Openresty lua client for redis cluster.
Apache License 2.0
376 stars 134 forks source link

Using `resty.redis` as lua variable at lua module level #82

Closed rishabh-gupta2 closed 3 years ago

rishabh-gupta2 commented 3 years ago

@steve0511 Referring to the limitations mentioned by openresty/lua-resty-redis

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?