Files
diary-news/scripts/_redis_check.py

28 lines
1.2 KiB
Python
Raw Normal View History

import os, paramiko
PW = os.environ["REMOTE_PASS"]
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("207.57.129.228", port=19717, username="root", password=PW, timeout=15, allow_agent=False, look_for_keys=False)
def run(cmd, t=15):
si, so, se = c.exec_command(cmd, timeout=t)
out = so.read().decode("utf-8", "replace")
err = se.read().decode("utf-8", "replace")
rc = so.channel.recv_exit_status()
if out: print(out, end="")
if err: print("[err]", err, end="", file=__import__("sys").stderr)
return out
# 拿 REDIS_PASSWORD
rpw = run("grep ^REDIS_PASSWORD /srv/news/.env | cut -d= -f2").strip()
print(f"REDIS_PASSWORD (前 6): {rpw[:6]}...")
# 直接 docker exec redis-cli 用 -a
print("\n--- 用 docker exec 直接查 ---")
run(f"docker exec news-aggregator-redis-1 redis-cli -a '{rpw}' GET translation:month:202606 2>&1")
run(f"docker exec news-aggregator-redis-1 redis-cli -a '{rpw}' KEYS 'translation:*' 2>&1")
# 看 API 容器里 service.py 调 add_usage 的逻辑
print("\n--- 测试 add_usage ---")
run(f"docker exec news-aggregator-api-1 python -c \"import asyncio; from app.services.translation.service import service; asyncio.run(service.add_usage(100)); print('done')\"", t=15)
c.close()