Hello!
On Mon, Nov 17, 2014 at 12:17 PM, Gaurav Kumar wrote:
> I need to put a string in a third party system (mongodb/redis etc) when
> using body_filter_by_lua. As per the documentation,
>
[...]
> when using body_filter_by_lua. I think it is due to the fact that redis
> library must be using ngx.socket or any of the functions which are disabled
> as per documentation.
>
The work-around is also officially documented :) To quote,
https://github.com/openresty/lua-nginx-module#cocockets-not-available-everywhere
"There exists a work-around, however, when the original context does
not need to wait for the cosocket results. That is, creating a 0-delay
timer via the ngx.timer.at API and do the cosocket results in the
timer handler, which runs asynchronously as to the original context
creating the timer."
BTW, for the best performance, you'd better buffer the messages on the
Lua land a little bit so that you can take advantage of the redis
pipelining feature to reduce the (expensive) redis roundtrips and
socket-related system calls. Or in other words, use the "batch
processing" model. The lua-resty-logger-socket library, for example,
uses this buffering model as well:
https://github.com/cloudflare/lua-resty-logger-socket
Best regards,
-agentzh