openresty / openresty/lua-resty-redis
lua tcp socket read timed out
Open
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 2k
- Forks
- 447
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 3
Description
@agentzh hello!
Here's my code, please help me,thank you!
local redis = require "resty.redis"
local cjson = require "cjson.safe"
local M = {}
local tab_getn = table.getn
local redisidx =60000
local max = 200
local timeout = 30000
local maxcount = 500
local count = 10
function M.connect(conf)
local red = redis:new()
red:set_timeout(timeout) -- 1 sec
local ok, err = red:connect(conf.host, conf.port)
if not ok then
ngx.log(ngx.ERR, "failed to connect redis: ", err)
ngx.sleep(1)
return M.connect(conf)
end
--red:set_timeout(timeout) -- 1 sec
return red
end
function M.rpop(red,name)
ngx.log(ngx.INFO,"---------rpop:"..tostring(name))
local res, err = red:rpop(name)
if not res then
ngx.log(ngx.ERR, "failed to pop redis : "..name, err) --lua tcp socket read timed out
return nil
end
ngx.log(ngx.INFO, "------------ rpop value:"..tostring(res))
local ok, err = red:set_keepalive(redisidx, max)
if not ok then
ngx.log(ngx.ERR,"failed to set keepalive: ", err)
end
ngx.log(ngx.INFO, "------------ get value:"..tostring(res))
return cjson.decode(res)
end
function M.rpoplen(red,name)
local list = {}
local len = count
ngx.log(ngx.INFO,"---------rpoplen:"..tostring(name))
while tab_getn(list)<maxcount and len >0 do
local res, err = red:rpop(name)
if not res then
ngx.log(ngx.ERR, "failed to rpoplen redis : "..name, err)
return nil
end
ngx.log(ngx.INFO, "------------ rpop value:"..tostring(res))
if res ~= ngx.null then
local mlist = cjson.decode(res)
if mlist then
local mlen = tab_getn(mlist)
if mlen == 0 then
break
end
for i=1, mlen do
list[#list+1] = mlist[i]
end
end
else
break
end
len = len -1
ngx.sleep(0.001)
end
local ok, err = red:set_keepalive(redisidx, max)
if not ok then
ngx.log(ngx.ERR,"failed to set keepalive: ", err)
end
if tab_getn(list)== 0 then
return nil
end
return list
end
function M.lpush(red,name,value)
ngx.log(ngx.INFO,"---------lpush:"..tostring(name))
local res, err = red:lpush(name, cjson.encode(value))
if not res then
ngx.log(ngx.ERR, "failed to lpush redis : "..name, err)
return
end
local ok, err = red:set_keepalive(redisidx, max)
if not ok then
ngx.log(ngx.ERR,"failed to set keepalive: ", err)
end
end
function M.rpush(red,name,value)
ngx.log(ngx.INFO,"---------rpush:"..tostring(name))
local res, err = red:rpush(name, cjson.encode(value))
if not res then
ngx.log(ngx.ERR, "failed to rpush redis : "..name, err)
return
end
local ok, err = red:set_keepalive(redisidx, max)
if not ok then
ngx.log(ngx.ERR,"failed to set keepalive: ", err)
end
end
return M
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The report provides an inline Lua example using M.connect and M.rpop, but names no repository file or test. Start by reproducing the Redis read timeout with the shown timeout and connection flow, then inspect the relevant lua-resty-redis socket handling. Done requires identifying the cause and verifying a documented fix or clear resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, redis
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100