lua-resty-redis
                                
                                 lua-resty-redis copied to clipboard
                                
                                    lua-resty-redis copied to clipboard
                            
                            
                            
                        Add luasocket-based redis interface
Useful in contexts where the cosocket api is not available - such as init_by_lua.
I used this to load a script into lua once, set a shared memory variable, and then use evalsha instead of sending the much larger script over the wire constantly.
Implementation here: https://github.com/chaoslawful/lua-nginx-module/issues/206#issuecomment-13041467
Hello!
On Sat, Feb 2, 2013 at 6:56 PM, Jose Diaz-Gonzalez <[email protected]
wrote:
Useful in contexts where the cosocket api is not available - such as init_by_lua.
I used this to load a script into lua once, set a shared memory variable, and then use evalsha instead of sending the much larger script over the wire constantly.
For your very case, instead of doing it in init_by_lua, another option is to do this initialization work at the first request and cache the results (or state) in Lua module level variables. See http://wiki.nginx.org/HttpLuaModule#Data_Sharing_within_an_Nginx_Worker :)
Because init_by_lua is running in the Nginx master process which usually runs with root access, it's also more dangerous to do a lot of work in it :)
Best regards, -agentzh
True, though separating the code to specify this once per nginx server is nice, and init_by_lua seems like the perfect place to do it.
Yes, it is dangerous, but in our case, it is trusted code that is running, not something that an external user is defining.
@josegonzalez I'd like to add a simple blocking implementation of the cosocket API for init_by_lua* (it does not matter at all to block there). Are you willing to contribute a patch? ;)
Sure. I think it was a two line change, but I'll see what I can do :) On Sep 27, 2013 6:49 PM, "Yichun Zhang" [email protected] wrote:
@josegonzalez https://github.com/josegonzalez I'd like to add a simple blocking implementation of the cosocket API for init_by_lua*. Are you willing to contribute a patch? ;)
— Reply to this email directly or view it on GitHubhttps://github.com/agentzh/lua-resty-redis/issues/14#issuecomment-25282740 .
@josegonzalez No, not really. The current implementation is nonblocking.
Oh I meant to make it use lua's socket class, was a trivial change.
:+1:
For an example, I want pull a stream list from redis in init_by_lua.
Thumbs up for cosocket (be it blocking or not blocking) at init_by_lua context.
@agentzh Any progress on this? Connecting to Redis to pull data before the server starts would be great.
Our current plan is to directly run an event loop in the init_by_lua* context and make cosockets directly work there.
@agentzh Great!