Files
wecom_it_smart_desk/scripts/debug_redis.py
Simon 7864ab404b feat(scripts): 收纳运维/部署/修复/调试脚本到 scripts/ 目录
**目录结构**:
- scripts/                 顶层运维/工具脚本(20 个)
- scripts/deploy/          一键部署脚本(deploy_*.py / upload_*.py / redeploy.py 等 8 个)
- scripts/fix/             一次性修复脚本(fix_*.py / fix_*.cypher / fix_*.sql 等 9 个)
- scripts/debug/           调试脚本集合(check_*.py/sql、test_*.py、debug_*.py 等 42 个)

**ops-tools/jms_ops.py**:jumpserver-ops skill 默认路径修复
- 从 'jumpserver-automation-shareable' 改为 'jumpserver-ops'
- 同步更新注释(优先 JP_SKILL_DIR 环境变量)

**典型脚本用途**:
- scripts/deploy-v1.2.ps1 / -staging.ps1:一键部署 v1.2 到生产 / staging
- scripts/init_quick_rules.sql:quick_rules 表初始数据
- scripts/gen_admin_token.py:生成 admin JWT token(调试用)
- scripts/build-and-verify.sh:v1.1 实施验证脚本
- scripts/verify_*.sh / .py:API/quick_rules 验证
- scripts/fix/*.py:环境修复(compose、env_key、itsm_bridge 等)

合计 81 文件 + 3317 行 / - 1 行
2026-08-03 18:48:02 +08:00

46 lines
1.1 KiB
Python

import redis
import json
import secrets
import sys
REDIS_PWD = "WKzl7jgKTkeWxFWGIBXfzokm59Gvfr76"
try:
r = redis.Redis(host="redis", port=6379, password=REDIS_PWD, db=0)
print("Redis connect OK")
# Ping
print(f"PING: {r.ping()}")
# Test write
r.setex("test:debug_token", 60, "test_value")
print(f"GET: {r.get('test:debug_token')}")
# 写 token
token = secrets.token_urlsafe(32)
user_info = {
"employee_id": "sxn",
"username": "admin",
"name": "宋献",
"role": "admin",
"department": "IT支持组",
"login_source": "test",
"login_method": "test_script",
"last_active": "2026-07-28T02:00:00",
}
r.setex(f"user:token:{token}", 8 * 3600, json.dumps(user_info, ensure_ascii=False))
print(f"Token written: {token}")
# 验证
val = r.get(f"user:token:{token}")
print(f"Stored: {val[:80] if val else 'None'}")
# 输出token到文件
with open("/tmp/test_token.txt", "w") as f:
f.write(token)
print(f"Token saved to /tmp/test_token.txt")
except Exception as e:
print(f"FAIL: {e}", file=sys.stderr)
sys.exit(1)