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"
|
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():
|
||||||
try:
|
state_json = r.get("tv-control-state")
|
||||||
with open("/app/state.json", "r") as f:
|
if state_json:
|
||||||
return json.load(f)
|
try:
|
||||||
except (FileNotFoundError, json.JSONDecodeError):
|
return json.loads(state_json)
|
||||||
|
except 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")
|
||||||
|
|||||||
Reference in New Issue
Block a user