Abd*_*eed 0 lua nginx redis openresty
这是我的配置:
local rc = require("resty.redis.connector").new({
connect_timeout = 50,
read_timeout = 5000,
keepalive_timeout = 30000
})
local redis, err1 = rc:connect({
url = "redis://127.0.0.1:6379",
})
if not redis then
ngx.say( err1)
else
ngx.say('connection fine')
end
local ok, err = rc:set_keepalive(redis)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
[错误] 4044#0:*1068056 尝试在关闭的套接字上发送数据:u:00007F2BABA05D48,c:0000000000000000,ft:0 eof:0,客户端:我的 IP,服务器:,请求:“GET /foo HTTP/1.1 ", 主机: "服务器 IP"
当我禁用 keepalive 设置时,出现此错误:
[错误] 4147#0: *1089971 lua tcp 套接字连接超时,连接到 127.0.0.1:6379 时,
当我注释掉与 rc:set_keepalive 相关的行时,它适用于单个请求并在 100 个请求上崩溃。
在大量请求下连接到 Lua 中的 Redis 的最佳实践是什么?
在 Lua 中使用 redis 最流行的方式是lua-resty-redis
关于[error] 4044#0: *1068056 attempt to send data on a closed socket
我在使用set_timeouts(connect_timeout, send_timeout, read_timeout) 方法时经历过它。
当我切换到set_timeout(time)方法时,错误消失了。
我没有使用过lua-resty-redis-connector,我假设你在你的代码中使用了它。