Fix Lua script execution failure for Redis cluster commands#7498
Hidden character warning
Fix Lua script execution failure for Redis cluster commands#7498PandaLIU-1111 wants to merge 4 commits intohyperf:masterfrom
Conversation
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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.
| return redis.error_reply('unsupported cmd: ' .. cmd) | ||
| end | ||
| redis.call('hSet', KEYS[1], '__meta', ARGV[4]) | ||
| redis.call('sAdd', KEYS[2], KEYS[1]) |
There was a problem hiding this comment.
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.
修复 redis 在集群版本下,执行 lua 脚本出现,
error: ERR bad lua script for redis cluster, first parameter of redis.call/redis.pcall must be a single literal string错误信息