31 lines
No EOL
964 B
Python
31 lines
No EOL
964 B
Python
|
|
import json
|
|
|
|
class ValkeyConfig:
|
|
def __init__(self, configJSON):
|
|
|
|
self.host = configJSON.get("host", "localhost")
|
|
|
|
try:
|
|
self.port = int(configJSON.get("port", 6379))
|
|
except ValueError:
|
|
Logger.error("Unable to parse config value 'valkey.port'.")
|
|
Logger.error("Ensure 'valkey.port' is a interger")
|
|
Logger.warn("Defaulting 'valkey.port' to 6379")
|
|
|
|
try:
|
|
self.db = int(configJSON.get("db", 0))
|
|
except ValueError:
|
|
Logging.error("Unable to parse config value 'valkey.db'")
|
|
Logger.error("Ensure 'valkey.db' is a number")
|
|
Logger.warn("Defaulting 'valkey.db' to 0")
|
|
|
|
self.enabled = configJSON.get("enabled", False if isinstance(configJSON.get("enabled"), bool) else False)
|
|
|
|
class Config:
|
|
|
|
def __init__(self, _configFilePath):
|
|
with open(_configFilePath) as _configFile:
|
|
_configJSON = json.load(_configFile)
|
|
_ValkeyJson = _configJSON.get("valkey", {})
|
|
self.valkeyConf = ValkeyConfig(_ValkeyJson) |