trigger bgsave on importent redis set_message

This commit is contained in:
Simon 2023-08-23 18:35:20 +07:00
parent 6151da821f
commit 3803537739
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 16 additions and 5 deletions

View File

@ -112,9 +112,9 @@ class CookieHandler:
def set_cookie(self, cookie): def set_cookie(self, cookie):
"""set cookie str and activate in cofig""" """set cookie str and activate in cofig"""
RedisArchivist().set_message("cookie", cookie) RedisArchivist().set_message("cookie", cookie, save=True)
path = ".downloads.cookie_import" path = ".downloads.cookie_import"
RedisArchivist().set_message("config", True, path=path) RedisArchivist().set_message("config", True, path=path, save=True)
self.config["downloads"]["cookie_import"] = True self.config["downloads"]["cookie_import"] = True
print("cookie: activated and stored in Redis") print("cookie: activated and stored in Redis")

View File

@ -100,7 +100,7 @@ class AppConfig:
self.config[config_dict][config_value] = to_write self.config[config_dict][config_value] = to_write
updated.append((config_value, to_write)) updated.append((config_value, to_write))
RedisArchivist().set_message("config", self.config) RedisArchivist().set_message("config", self.config, save=True)
return updated return updated
@staticmethod @staticmethod
@ -112,7 +112,7 @@ class AppConfig:
message = {"status": value} message = {"status": value}
redis_key = f"{user_id}:{key}" redis_key = f"{user_id}:{key}"
RedisArchivist().set_message(redis_key, message) RedisArchivist().set_message(redis_key, message, save=True)
def get_colors(self): def get_colors(self):
"""overwrite config if user has set custom values""" """overwrite config if user has set custom values"""
@ -225,7 +225,7 @@ class ScheduleBuilder:
to_write = value to_write = value
redis_config["scheduler"][key] = to_write redis_config["scheduler"][key] = to_write
RedisArchivist().set_message("config", redis_config) RedisArchivist().set_message("config", redis_config, save=True)
mess_dict = { mess_dict = {
"status": self.MSG, "status": self.MSG,
"level": "info", "level": "info",

View File

@ -41,6 +41,7 @@ class RedisArchivist(RedisBase):
message: dict, message: dict,
path: str = ".", path: str = ".",
expire: bool | int = False, expire: bool | int = False,
save: bool = False,
) -> None: ) -> None:
"""write new message to redis""" """write new message to redis"""
self.conn.execute_command( self.conn.execute_command(
@ -54,6 +55,16 @@ class RedisArchivist(RedisBase):
secs = expire secs = expire
self.conn.execute_command("EXPIRE", self.NAME_SPACE + key, secs) self.conn.execute_command("EXPIRE", self.NAME_SPACE + key, secs)
if save:
self.bg_save()
def bg_save(self) -> None:
"""save to aof"""
try:
self.conn.bgsave()
except redis.exceptions.ResponseError:
pass
def get_message(self, key: str) -> dict: def get_message(self, key: str) -> dict:
"""get message dict from redis""" """get message dict from redis"""
reply = self.conn.execute_command("JSON.GET", self.NAME_SPACE + key) reply = self.conn.execute_command("JSON.GET", self.NAME_SPACE + key)