lua-resty-core
基于 FFI 的 ngx_lua 模块新 Lua API
$ opm get openresty/lua-resty-core
名称
lua-resty-core - 基于 FFI 的 ngx_http_lua_module 和/或 ngx_stream_lua_module 的新 Lua API
状态
此库已准备好投入生产。
概要
# nginx.conf
http {
# you do NOT need to configure the following line when you
# are using the OpenResty bundle 1.4.3.9+.
lua_package_path "/path/to/lua-resty-core/lib/?.lua;;";
init_by_lua_block {
require "resty.core"
collectgarbage("collect") -- just to collect any garbage
}
...
}
描述
此纯 Lua 库使用 LuaJIT FFI 重新实现了 ngx_lua 模块的 Nginx API for Lua 的一部分,并将新的基于 FFI 的 Lua API 安装到 ngx_lua 模块使用的 ngx. 和 ndk. 命名空间中。
此外,此 Lua 库将 ngx_lua 模块的任何重要的新 Lua API 实现了为适当的 Lua 模块,如 ngx.semaphore 和 ngx.balancer。
基于 FFI 的 Lua API 可以与 LuaJIT 的 JIT 编译器一起使用。ngx_lua 的默认 API 基于标准 Lua C API,该 API 永远不会被 JIT 编译,用户 Lua 代码始终被解释(速度慢)。
对新的 ngx_stream_lua_module 的支持也已开始。
此库默认情况下随 OpenResty 捆绑包一起提供。因此,您实际上无需担心依赖项和要求。
先决条件
警告 此库包含在每个 OpenResty 版本中。您应该使用您使用的特定 OpenResty 版本中捆绑的此库版本。否则,您可能会遇到严重的兼容性问题。
LuaJIT 2.1(目前,它是官方 luajit-2.0 git 仓库中的 v2.1 git 分支:http://luajit.org/download.html)
ngx_http_lua_module v0.10.13 或更高版本。
ngx_stream_lua_module v0.0.5 或更高版本。
实现的 API
resty.core.hash
resty.core.base64
resty.core.uri
resty.core.regex
resty.core.exit
resty.core.shdict
resty.core.var
resty.core.ctx
resty.core.request
ngx.req.set_header(部分:尚未支持表类型的标头值)
resty.core.response
resty.core.misc
resty.core.time
resty.core.worker
resty.core.phase
ngx.semaphore
此 Lua 模块实现了一个信号量 API,用于高效的“轻量级线程”同步,该 API 可以在不同请求之间工作(但不能跨 nginx 工作进程)。
有关更多详细信息,请参阅此 Lua 模块的 文档。
ngx.balancer
此 Lua 模块实现用于在 Lua 中定义动态上游负载均衡器。
有关更多详细信息,请参阅此 Lua 模块的 文档。
ngx.ssl
此 Lua 模块提供了一个 Lua API,用于在 NGINX 下游 SSL 握手过程中控制 SSL 证书、私钥、SSL 协议版本等。
有关更多详细信息,请参阅此 Lua 模块的 文档。
ngx.ssl.session
此 Lua 模块提供了一个 Lua API,用于操作 NGINX 下游 SSL 连接的 SSL 会话数据和 ID。
有关更多详细信息,请参阅此 Lua 模块的 文档。
ngx.re
此 Lua 模块提供了一个 Lua API,它实现了对 ngx.re
API 的便捷实用程序。
有关更多详细信息,请参阅此 Lua 模块的 文档。
ngx.resp
此 Lua 模块提供了一个 Lua API,可用于处理 HTTP 响应。
有关更多详细信息,请参阅此 Lua 模块的 文档。
ngx.process
此 Lua 模块用于在 Lua 中管理 nginx 进程。
有关更多详细信息,请参阅此 Lua 模块的 文档。
此模块最早在 lua-resty-core v0.1.12 中引入。
ngx.errlog
此 Lua 模块提供了一个 Lua API,用于捕获和管理 nginx 错误日志消息。
有关更多详细信息,请参阅此 Lua 模块的 文档。
此模块最早在 lua-resty-core v0.1.12 中引入。
ngx.base64
此 Lua 模块提供了一个 Lua API,用于对 urlsafe base64 进行编码/解码。
有关更多详细信息,请参阅此 Lua 模块的 文档。
此模块最早在 lua-resty-core v0.1.14 中引入。
注意事项
如果用户 Lua 代码没有被 JIT 编译,那么使用此库可能会导致解释模式下的性能下降。只有在您的用户 Lua 代码中很大一部分被 JIT 编译时,您才会观察到加速。
待办事项
使用 FFI 重新实现
ngx_lua
的 cosocket API。使用 FFI 重新实现
ngx_lua
的ngx.eof
和ngx.flush
API 函数。
作者
Yichun "agentzh" Zhang (章亦春) <[email protected]>,OpenResty Inc.
版权和许可
此模块根据 BSD 许可证授权。
版权所有 (C) 2013-2018,作者 Yichun "agentzh" Zhang,OpenResty Inc.
保留所有权利。
在满足以下条件的情况下,允许以源代码和二进制形式重新分发和使用此软件,无论是否修改:
源代码的再分发必须保留上述版权声明、此条件列表和以下免责声明。
二进制形式的再分发必须在随分发提供的文档和/或其他材料中复制上述版权声明、此条件列表和以下免责声明。
本软件由版权所有者和贡献者“按原样”提供,不提供任何明示或暗示的保证,包括但不限于对适销性和特定用途适用性的暗示保证。在任何情况下,版权所有者或贡献者均不对任何直接、间接、偶然、特殊、示例性或后果性损害(包括但不限于替代商品或服务的采购;使用、数据或利润损失;或业务中断)负责,无论其原因如何,以及无论责任理论如何,无论是在合同、严格责任或侵权行为(包括疏忽或其他原因)中,因使用本软件而产生的或与本软件相关的任何方式引起的。
另请参阅
ngx_lua 模块:https://github.com/openresty/lua-nginx-module#readme
LuaJIT FFI:http://luajit.org/ext_ffi.html
作者
Yichun "agentzh" Zhang (agentzh)
许可证
2bsd
依赖项
openresty/lua-resty-lrucache >= 0.08, luajit >= 2.1.0, nginx >= 1.13.6, ngx_http_lua = 0.10.13
版本
-
openresty/lua-resty-core 0.1.15基于 FFI 的 ngx_lua 模块的新 Lua API 2018-04-22 18:48:07
-
openresty/lua-resty-core 0.1.14基于 FFI 的 ngx_lua 模块的新 Lua API 2018-04-19 20:14:32
-
openresty/lua-resty-core 0.1.13基于 FFI 的 ngx_lua 模块的新 Lua API 2017-09-26 06:20:19
-
openresty/lua-resty-core 0.1.12基于 FFI 的 ngx_lua 模块的新 Lua API 2017-08-08 22:10:58
-
openresty/lua-resty-core 0.1.11基于 FFI 的 ngx_lua 模块的新 Lua API 2017-04-08 22:39:47
-
openresty/lua-resty-core 0.1.8基于 FFI 的 ngx_lua 模块的新 Lua API 2016-09-29 03:02:35