riak: 基于 cosocket API 的 NGINX 模块 Lua riak 协议缓冲客户端驱动
安装
如果您尚未设置 RPM 仓库订阅,请 注册。然后您可以继续以下步骤。
CentOS/RHEL 7 或 Amazon Linux 2
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install lua-resty-riak
CentOS/RHEL 8+、Fedora Linux、Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install lua5.1-resty-riak
要在 NGINX 中使用此 Lua 库,请确保已安装 nginx-module-lua。
本文档描述了 lua-resty-riak v2.0.0,发布于 2013 年 12 月 05 日。
lua-resty-riak - 基于 cosocket API 的 ngx_lua 的 Lua riak 协议缓冲客户端驱动。
最初基于 lua-resty-memcached 库。
受 riak-client-ruby 的影响。
描述
此 Lua 库是 ngx_lua nginx 模块 的 riak 协议缓冲客户端驱动。
此 Lua 库利用了 ngx_lua 的 cosocket API,确保 100% 非阻塞行为。
请注意,至少需要 ngx_lua 0.5.0rc29 或 ngx_openresty 1.0.15.7。
依赖以下 Lua 模块:
- lua-pb - https://github.com/Neopallium/lua-pb
- struct - http://www.inf.puc-rio.br/~roberto/struct/
- lpack - http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lpack
概述
location /t {
content_by_lua '
require "luarocks.loader"
local riak = require "resty.riak"
local client = riak.new()
local ok, err = client:connect("127.0.0.1", 8087)
if not ok then
ngx.log(ngx.ERR, "connect failed: " .. err)
end
local bucket = client:bucket("test")
local object = bucket:new("1")
object.value = "test"
object.content_type = "text/plain"
local rc, err = object:store()
ngx.say(rc)
local object, err = bucket:get("1")
if not object then
ngx.say(err)
else
ngx.say(object.value)
end
client:close()
';
}
用法
请参阅 生成的文档 以获取用法和示例。
注意 高级 API 应被视为 稳定 - 即在小版本之间不会破坏。 低级 或 原始 API 不应被视为稳定。
2.0 中的潜在破坏性更改
2.0.0 现在使用 向量时钟 来处理对象的获取、设置和删除。如果您使用的桶允许多个值(兄弟),则这可能会破坏您的应用程序。
限制
- 此库不能在 set_by_lua、log_by_lua 和 header_filter_by_lua 等代码上下文中使用,因为 ngx_lua cosocket API 不可用。
resty.riak对象实例不能在 Lua 模块级别的 Lua 变量中存储,因为这将被同一 nginx 工作进程处理的所有并发请求共享(请参见 Nginx 工作进程中的数据共享),并在并发请求尝试使用相同实例时导致不良的竞争条件。您应始终在函数局部变量或ngx.ctx表中初始化这些对象。这些地方对每个请求都有自己的数据副本。
GitHub
您可以在 nginx-module-riak 的 GitHub 仓库 中找到此模块的其他配置提示和文档。