Files
inquiry_robot/inquiry-agent/agent/redis_coord/keys.py
T

51 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Redis 键名拼装。
本文件职责:所有 Redis key 必须带 REDIS_KEY_PREFIX,避免与现网 ytd:prod: 冲突。
说明:Redis 的「db1」是连接 URL 里的数字库号(/1),不是库名;
可读业务名靠前缀 inquiry_robot:(见 prompt/14、13)。
禁止:写入 checkpoint / 六态 / Worker 全局单例锁键。
"""
from __future__ import annotations
def normalize_prefix(prefix: str) -> str:
"""
规范化前缀:去掉首尾空白,确保以冒号结尾便于拼接。
例:inquiry_robot → inquiry_robot:
"""
p = (prefix or "").strip()
if not p:
return "inquiry_robot:"
return p if p.endswith(":") else f"{p}:"
def join_key(prefix: str, *parts: str) -> str:
"""
拼完整 key:{prefix}{part1}:{part2}:…
参数 parts 不得包含前缀本身;空段丢弃。
"""
base = normalize_prefix(prefix)
segs = [str(p).strip(":") for p in parts if p is not None and str(p).strip() != ""]
if not segs:
return base.rstrip(":")
return base + ":".join(segs)
# 约定后缀(骨架);正式业务可扩展,勿改成无前缀的裸键
STREAM_LLM = "stream:llm"
STREAM_RECOGNITION = "stream:recognition"
STREAM_PDF = "stream:pdf"
STREAM_ARCHIVE = "stream:archive"
STREAM_WAKE = "stream:wake"
IDEMPOTENCY = "idem"
RATE_LIMIT = "ratelimit"
TOKEN_WECOM = "token:wecom"
TOKEN_COPY_TICKET = "token:copy_ticket"
TOKEN_JSAPI = "token:jsapi"
# Worker 出完报价文件后写给 HTTP:短协调,不当六态
QUOTE_FILE_READY = "quote_file_ready"