fix: Redis target_database隔离修复 - _parse_redis_commands使用ticket.target_database作为默认db编号,修复简单文本格式写死db=0的bug,确保工单提交到db1时数据正确写入db1
This commit is contained in:
1 parent
b92c3399e1
commit
8f962a988f
2 files changed
+25
-8
No files matched your search
@@ -520,7 +520,7 @@ class TicketExecutor:
|
||||
|
||||
try:
|
||||
# 解析命令
|
||||
commands = self._parse_redis_commands(ticket.sql_content)
|
||||
commands = self._parse_redis_commands(ticket.sql_content, ticket.target_database)
|
||||
if not commands:
|
||||
report.status = "failed"
|
||||
report.errors.append("未解析到有效的 Redis 命令")
|
||||
@@ -1552,13 +1552,14 @@ class TicketExecutor:
|
||||
return row or 0
|
||||
|
||||
@staticmethod
|
||||
def _parse_redis_commands(content: str) -> List[Dict[str, Any]]:
|
||||
def _parse_redis_commands(content: str, target_database: str = "0") -> List[Dict[str, Any]]:
|
||||
"""解析 Redis 工单内容为命令列表。
|
||||
|
||||
支持 JSON 格式和简单文本格式。
|
||||
|
||||
Args:
|
||||
content: 工单内容
|
||||
target_database: 目标 DB 编号(来自 ticket.target_database)
|
||||
|
||||
Returns:
|
||||
命令列表,每项为 {"command": str, "db": int}
|
||||
@@ -1567,6 +1568,12 @@ class TicketExecutor:
|
||||
if not content:
|
||||
return []
|
||||
|
||||
# 解析默认 db 编号
|
||||
try:
|
||||
default_db = int(target_database)
|
||||
except (ValueError, TypeError):
|
||||
default_db = 0
|
||||
|
||||
# 尝试 JSON 解析
|
||||
if content.startswith("{"):
|
||||
try:
|
||||
@@ -1577,14 +1584,14 @@ class TicketExecutor:
|
||||
if isinstance(cmd, dict) and "command" in cmd:
|
||||
commands.append({
|
||||
"command": cmd["command"],
|
||||
"db": cmd.get("db", 0),
|
||||
"db": cmd.get("db", default_db),
|
||||
})
|
||||
elif isinstance(cmd, str):
|
||||
commands.append({"command": cmd, "db": 0})
|
||||
commands.append({"command": cmd, "db": default_db})
|
||||
return commands
|
||||
# 可能是单条命令的 JSON
|
||||
if "command" in data:
|
||||
return [{"command": data["command"], "db": data.get("db", 0)}]
|
||||
return [{"command": data["command"], "db": data.get("db", default_db)}]
|
||||
except json.JSONDecodeError:
|
||||
pass # 不是 JSON,尝试文本格式
|
||||
|
||||
@@ -1593,7 +1600,7 @@ class TicketExecutor:
|
||||
for line in content.split("\n"):
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#"):
|
||||
commands.append({"command": line, "db": 0})
|
||||
commands.append({"command": line, "db": default_db})
|
||||
|
||||
return commands
|
||||
|
||||
|
||||
Reference in new issue
Block a user