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"
r = redis.Redis(host='194.15.36.205',username="default", port=12004, db=12, password=os.getenv("REDIS"))
def _read_state():
try:
with open("/app/state.json", "r") as f:
return json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
state_json = r.get("tv-control-state")
if state_json:
try:
return json.loads(state_json)
except json.JSONDecodeError:
return dict(DEFAULT_STATE)
else:
return dict(DEFAULT_STATE)
def _write_state(state):
with open("/app/state.json", "w") as f:
json.dump(state, f)
r.set("tv-control-state", json.dumps(state))
def main(args):
route = args.get("route")