New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime error: attempt to yield across C-call boundary due to lua-resty-redis connect()
invocation
#5
Comments
connect()
invokationconnect()
invokation
Hmm, I've solved this issue with tricky workaround: redis_wrapper.lua local redis_wrapper_meta = {
__index = function(self, method)
if not rawget(self, 'redis_obj') then
local redis_obj, err = require('lapis.redis').get_redis()
if not redis_obj then
error('lapis.redis error: ' .. err)
end
local config = require('lapis.config').get()
if config.redis.db then
redis_obj:select(config.redis.db)
end
self.redis_obj = redis_obj
end
return self.redis_obj[method]
end
}
return setmetatable({}, redis_wrapper_meta) app.lua local redis = require('redis_wrapper')
redis:set('foo', 'bar') I think I can implement same lazy connect trick in lapis-redis module with optional In addition, It would be great to be able to specify db number in config along with host/port. What do you think about these ideas? |
connect()
invokationconnect()
invocation
You have to call You can't have a global redis connection per worker because workers can be processing multiple http requests at once when they yield due to asynchronous operations. |
Thanks for clarifying! Now I realized that the redis object (as a “singleton”) instantiating mechanism is already implemented in |
lapis 1.5.0-2
lapis-redis dev-1
openresty 1.9.15.1
nginx.conf:
config.lua
app.lua:
exception:
I found this issue, but I don't understand how this error can be fixed.
The text was updated successfully, but these errors were encountered: