Basic Redis connection configuration
This commit is contained in:
parent
8ee608364f
commit
6e6ae931f7
5 changed files with 49 additions and 14 deletions
6
src/rectes/redis_db.py
Normal file
6
src/rectes/redis_db.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
# noinspection PyUnresolvedReferences,PyProtectedMember
|
||||
from redis import asyncio as aioredis
|
||||
|
||||
from rectes.settings import settings
|
||||
|
||||
redis = aioredis.from_url(settings.redis.url)
|
27
src/rectes/settings.py
Normal file
27
src/rectes/settings.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import os
|
||||
|
||||
import tomllib
|
||||
|
||||
|
||||
class Settings:
|
||||
def __init__(self, data: dict = None):
|
||||
if data:
|
||||
self._data = data
|
||||
else:
|
||||
with open(
|
||||
os.getenv("RECTES_CONF_FILE", "/etc/rectes/rectes.toml"), "rb"
|
||||
) as f:
|
||||
self._data = tomllib.load(f)
|
||||
|
||||
def __getattr__(self, item):
|
||||
try:
|
||||
value = self._data[item]
|
||||
except KeyError:
|
||||
raise AttributeError
|
||||
if isinstance(value, dict):
|
||||
return Settings(data=value)
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
settings = Settings()
|
Loading…
Add table
Add a link
Reference in a new issue