feat: refactor state management to use Redis instead of file storage
This commit is contained in:
@@ -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():
|
||||
state_json = r.get("tv-control-state")
|
||||
if state_json:
|
||||
try:
|
||||
with open("/app/state.json", "r") as f:
|
||||
return json.load(f)
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user