[英]Connection in Redis and Lua
This is my config: 这是我的配置:
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)
I'm getting this error: 我收到此错误:
[error] 4044#0: *1068056 attempt to send data on a closed socket: u:00007F2BABA05D48, c:0000000000000000, ft:0 eof:0, client: MY IP, server: , request: "GET /foo HTTP/1.1", host: "SERVER IP"
[错误] 4044#0:* 1068056尝试在封闭的套接字上发送数据:u:00007F2BABA05D48,c:0000000000000000,ft:0 eof:0,客户端:MY IP,服务器:,请求:“ GET / foo HTTP / 1.1 ”,主机:“ SERVER IP”
When I disable keepalive setting, get this error: 当我禁用keepalive设置时,出现此错误:
[error] 4147#0: *1089971 lua tcp socket connect timed out, when connecting to 127.0.0.1:6379,
[错误] 4147#0:* 1089971 lua tcp套接字连接超时,当连接到127.0.0.1:6379时,
When I comment out the line related to rc:set_keepalive it works on single requests and crashes on 100 requests. 当我注释掉与rc:set_keepalive相关的行时,它适用于单个请求,并且崩溃于100个请求。
What is the best practices for connecting to Redis in Lua under huge requests? 在大量需求下连接Lua中的Redis的最佳实践是什么?
Most popular way of using redis in Lua is lua-resty-redis 在Lua中使用Redis的最流行方法是lua-resty-redis
Regarding [error] 4044#0: *1068056 attempt to send data on a closed socket
I have experienced it when using set_timeouts(connect_timeout, send_timeout, read_timeout)
method. 关于
[error] 4044#0: *1068056 attempt to send data on a closed socket
在使用set_timeouts(connect_timeout, send_timeout, read_timeout)
方法时,我遇到了这种情况。
When I switched to set_timeout(time)
method the error was gone. 当我切换到
set_timeout(time)
方法时,错误消失了。
I have not used lua-resty-redis-connector which I assume your are using in your code. 我没有使用过lua-resty-redis-connector ,我假设您正在代码中使用它。
Your code is incorrect. 您的代码不正确。
ok, err
. ok, err
。 It doesn't make sense to pass ok
value to set_keepalive
. ok
值传递给set_keepalive
没有任何意义。 RTFM, please, all your code looks like one big mess, sorry. RTFM,对不起,您的所有代码看起来都一团糟。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.