redis-query
SKILL.md
Redis 只读查询 Skill
脚本
python3 scripts/redis_query.py --ins <实例名> --cmd <命令> [参数...]
配置
配置文件 ~/.weplay_ai_proxy.json(所有 AI Proxy skill 共用):
{
"agent_name": "oxagent",
"agent_token": "<token>",
"default_env": "online"
}
也可通过环境变量覆盖:WEPLAY_AI_AGENT_TOKEN。
agent_user_id 获取规则
- 只使用对话上下文 — 必须使用当前对话里随飞书消息带来的发送者 ID,并通过
--agent-user-id传入 - 禁止回退 — 不要从环境变量或
~/.weplay_ai_proxy.json读取agent_user_id - 拿不到就先问/先停 — 如果当前上下文拿不到飞书发送者 ID,不要臆造或复用其他 ID,先向用户确认再继续
快速参考
# 显式指定区服
python3 scripts/redis_query.py --region C --agent-user-id <feishu_sender_id> --ins login --cmd GET wespy_loginserver:userinfo:12345
# 指定区服和环境
python3 scripts/redis_query.py --region A --env online --agent-user-id <feishu_sender_id> --ins login --cmd GET wespy_loginserver:userinfo:12345
# 检查 key 类型和过期
python3 scripts/redis_query.py --region C --agent-user-id <feishu_sender_id> --ins login --cmd TYPE wespy_loginserver:userinfo:12345
python3 scripts/redis_query.py --region C --agent-user-id <feishu_sender_id> --ins login --cmd TTL wespy_loginserver:userinfo:12345
# 读取 hash 字段
python3 scripts/redis_query.py --region C --agent-user-id <feishu_sender_id> --ins login --cmd HGET user:profile:12345 nickname
# 查看 sorted set Top 10(带分数)
python3 scripts/redis_query.py --region C --agent-user-id <feishu_sender_id> --ins login --cmd ZREVRANGE rank:daily:gift 0 9 WITHSCORES
# 大值分段读取
python3 scripts/redis_query.py --region C --agent-user-id <feishu_sender_id> --ins login --cmd STRLEN big:key
python3 scripts/redis_query.py --region C --agent-user-id <feishu_sender_id> --ins login --cmd GETRANGE big:key 0 4095
# 列出可用区服
python3 scripts/redis_query.py --list-regions
区服
通过 --region 指定区服(代码、中文名、别名均可),不确定时用 --list-regions 查看完整列表。
区服推断优先级
- 用户明确指定 — 对话中直接给出区服
- 提问人职位/岗位 — 若对话上下文包含提问人的职位信息且职位中带有区服相关关键词(如「华语服运营」→ C、「日服QA」→ J),优先采用该区服
- 主动询问 — 以上仍无法确定时,直接向用户确认目标区服;不要读取
default_region或任何隐式默认区服
允许的命令
EXISTS GET GETRANGE STRLEN TTL PTTL TYPE HGET HEXISTS HLEN HSTRLEN LLEN LRANGE SCARD SISMEMBER ZCARD ZCOUNT ZRANGE ZREVRANGE ZRANK ZREVRANK ZSCORE
限制
GET/HGET自动预检值大小,超过 4096 字节拒绝,需改用GETRANGE分段读取LRANGE/ZRANGE/ZREVRANGE单次最多 50 个元素GETRANGE单次最多 4096 字节- 每 10 秒最多 10 次调用,单实例最大并发 4
- 请求超时或失败时最多重试一次,禁止循环重试
敏感 key 黑名单(禁止访问)
wespy_coinserver:user_coin:/wespy_coinserver:user_coin_change_log:wespy_loginserver:order_total_charge_rank/wespy_loginserver:web_order_fingerprint:/wespy_loginserver:official_charge_coin:/wespy_loginserver:apple_tx_history_order_state:wespy_loginserver:user_pay_info:
环境选择
- 优先使用显式
--env - 未传
--env时使用~/.weplay_ai_proxy.json里的default_env - 两者都没有时默认使用
online - 当用户未明确指定环境(test / online)且无法从上下文推断时,应主动询问用户目标环境再执行查询
查询策略
根据代码上下文判断 key 的数据类型,直接使用对应读命令查值(如 GET、HGET、ZREVRANGE 等)。值过大被拒时改用 GETRANGE 分段读。仅在完全无法从代码推断类型时才用 TYPE 探测。