Skip to content

fix/recovery mechanism for orphan streams #18

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

Merged
merged 3 commits into from
Jan 20, 2025

Conversation

stanley2058
Copy link
Collaborator

Now, the stream will try to add itself to y:worker on the socket connection.

@Yukaii Yukaii merged commit b361280 into main Jan 20, 2025
1 check passed
Comment on lines +123 to +144
checkAndRecoverWorkerStream: redis.defineScript({
NUMBER_OF_KEYS: 1,
SCRIPT: `
local found = false
local messages = redis.call("XREAD", "COUNT", 0, "STREAMS", "${this.redisWorkerStreamName}", "0-0")

if messages and #messages > 0 then
local entries = messages[1][2]
for _, entry in ipairs(entries) do
-- Each entry is an array where entry[2] is the message fields
if entry[2][2] == KEYS[1] then
found = true
break
end
end
end

-- If stream not found in y:worker and the stream exists, add it
if not found and redis.call("TYPE", KEYS[1]).ok == "stream" then
redis.call("XADD", "${this.redisWorkerStreamName}", "*", "compact", KEYS[1])
end
`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加上這個 redis 的 CPU 或是記憶體會有顯著的用量提升嗎?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local 看不太出來,目前只讓他在連線時跑一次

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.

4 participants