Skip to content

Fix Lua script execution failure for Redis cluster commands#7498

Open
PandaLIU-1111 wants to merge 4 commits intohyperf:masterfrom
PandaLIU-1111:修复普罗米修斯使用-redis-集群版本执行-lua-脚本失败的问题

Hidden character warning

The head ref may contain hidden characters: "\u4fee\u590d\u666e\u7f57\u7c73\u4fee\u65af\u4f7f\u7528-redis-\u96c6\u7fa4\u7248\u672c\u6267\u884c-lua-\u811a\u672c\u5931\u8d25\u7684\u95ee\u9898"
Open

Fix Lua script execution failure for Redis cluster commands#7498
PandaLIU-1111 wants to merge 4 commits intohyperf:masterfrom
PandaLIU-1111:修复普罗米修斯使用-redis-集群版本执行-lua-脚本失败的问题

Conversation

@PandaLIU-1111
Copy link
Copy Markdown
Member

@PandaLIU-1111 PandaLIU-1111 commented Aug 13, 2025

修复 redis 在集群版本下,执行 lua 脚本出现, error: ERR bad lua script for redis cluster, first parameter of redis.call/redis.pcall must be a single literal string 错误信息

@PandaLIU-1111 PandaLIU-1111 requested a review from Copilot August 13, 2025 03:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes Lua script execution failures in Redis cluster environments by replacing dynamic command execution with explicit command calls. The changes ensure that Prometheus metric operations work correctly in clustered Redis setups where dynamic command evaluation may be restricted.

Key changes:

  • Replace dynamic redis.call(ARGV[1], ...) with explicit command conditionals in gauge update script
  • Replace dynamic command execution with explicit conditionals in counter update script
  • Add proper error handling for unsupported commands

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

return redis.error_reply('unsupported cmd: ' .. cmd)
end
redis.call('hSet', KEYS[1], '__meta', ARGV[4])
redis.call('sAdd', KEYS[2], KEYS[1])
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

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

The metadata update logic is now executed unconditionally for all commands, but previously it was only executed when the hSet command returned 1 (new field) or when increment commands returned the expected value. This could lead to unnecessary metadata updates and performance issues.

Copilot uses AI. Check for mistakes.
return redis.error_reply('unsupported cmd: ' .. cmd)
end
redis.call('hSet', KEYS[1], '__meta', ARGV[4])
redis.call('sAdd', KEYS[2], KEYS[1])
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

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

The set addition is now executed unconditionally for all commands, but previously it was only executed when hSet returned 1 or when increment commands returned the expected value. This could lead to unnecessary operations and incorrect set membership tracking.

Copilot uses AI. Check for mistakes.
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.

2 participants