feat: refactor state management to use Redis instead of file storage

This commit is contained in:
2026-03-01 15:11:24 +01:00
parent cb8007074e
commit 44b4277b8e

View File

@@ -30,16 +30,19 @@ MINIO_CLIENT = Minio(
) )
BUCKET = "tv-control" BUCKET = "tv-control"
r = redis.Redis(host='194.15.36.205',username="default", port=12004, db=12, password=os.getenv("REDIS")) r = redis.Redis(host='194.15.36.205',username="default", port=12004, db=12, password=os.getenv("REDIS"))
def _read_state(): def _read_state():
state_json = r.get("tv-control-state")
if state_json:
try: try:
with open("/app/state.json", "r") as f: return json.loads(state_json)
return json.load(f) except json.JSONDecodeError:
except (FileNotFoundError, json.JSONDecodeError): return dict(DEFAULT_STATE)
else:
return dict(DEFAULT_STATE) return dict(DEFAULT_STATE)
def _write_state(state): def _write_state(state):
with open("/app/state.json", "w") as f: r.set("tv-control-state", json.dumps(state))
json.dump(state, f)
def main(args): def main(args):
route = args.get("route") route = args.get("route")