Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:异步模式下消费者无法消费的bug #13

Merged
merged 2 commits into from
Mar 26, 2024
Merged

Conversation

by1aN
Copy link
Contributor

@by1aN by1aN commented Mar 22, 2024

异步生成消费模式下,会有个bug:生产者不断往队列写入数据,但是消费者一直没有消费。
是因为在执行pending2ReadyScript脚本的时候,如果此时只有一条数据,就会跳过LPush的操作,导致readyKey里一直没有数据,现在把判断#args>2改成#args>0就可以了。

local msgs = redis.call('ZRangeByScore', KEYS[1], '0', ARGV[1])  -- get ready msg
if (#msgs == 0) then return end
local args2 = {} -- keys to push into ready
for _,v in ipairs(msgs) do
	table.insert(args2, v) 
    if (#args2 == 4000) then
		redis.call('LPush', KEYS[2], unpack(args2))
		args2 = {}
	end
end
#这里需要改成args>0
if (#args2 > 2) then 
	redis.call('LPush', KEYS[2], unpack(args2))
end
redis.call('ZRemRangeByScore', KEYS[1], '0', ARGV[1])  -- remove msgs from pending
return #msgs

@HDT3213
Copy link
Owner

HDT3213 commented Mar 26, 2024

原来 args 里面有 LPush readykey 两个参数的, 后来适配阿里云集群的时候拿出来了,但是判断条件忘记改了

@HDT3213
Copy link
Owner

HDT3213 commented Mar 26, 2024

你的测试用例会阻塞,这样过不了 CI

@by1aN
Copy link
Contributor Author

by1aN commented Mar 26, 2024

你的测试用例会阻塞,这样过不了 CI

改了一下:-D

@HDT3213 HDT3213 merged commit b4e9e62 into HDT3213:master Mar 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants