如何在init_by_lua中进行非阻塞调用

init_worker_by_lua_block {
  ....
  ngx.timer.every(10, MyFunction)
}

function MyFunction()
  local response = requests.get { url = url, headers = h }.
  ...

其中 MyFunction 通过 "requests" 发送 http 请求。 这会导致每 10 秒阻塞传入请求。 如何使其无阻塞?

点赞
用户2060502
用户2060502

假设您使用lua-resty-requests库。

在定时器上下文中,lua-resty-requests使用非阻塞cosocket API,因此不应该阻塞。

2019-10-21 09:45:19