cuiweixie / lua-resty-redis-cluster

a openresty redis cluster client
100 stars 70 forks source link

limitations? #3

Closed zh3linux closed 8 years ago

zh3linux commented 8 years ago

code

    if ngx.ctx.cache == nil then
        ngx.ctx.cache = redis_cluster:new(config.redis_config)
    end
    local v, err = ngx.ctx.cache:get(key)

In the case of concurrent will appear such mistakes

2016/05/27 09:52:12 [error] 32291#0: *30184 lua entry thread aborted: runtime error: /opt/apps/zkv/lua/resty/rediscluster.lua:217: bad request

The resty.redis object instance cannot be stored in a Lua variable at the Lua module level, 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).

https://github.com/openresty/lua-resty-redis#limitations

How should I solve this problem?

thx

zh3linux commented 8 years ago

https://github.com/cuiweixie/lua-resty-redis-cluster/blob/master/lib/resty/rediscluster.lua#L212

I change the 212nd lines of code for the rediscluster.lua file

<            redis_client = redis:new()
---
>             local redis_client = redis:new()

and it is working now.