From f90b53540fcbb160a82a606e91e060fc9bbaa15b Mon Sep 17 00:00:00 2001 From: Gabriel Gazola Milan Date: Mon, 30 Oct 2023 16:10:17 -0300 Subject: [PATCH] chore: split redis envs --- app/cache.py | 15 +++++++++++++-- app/config/base.py | 10 ++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/cache.py b/app/cache.py index 317b5b9..2276e41 100644 --- a/app/cache.py +++ b/app/cache.py @@ -1,13 +1,24 @@ # -*- coding: utf-8 -*- from aioredis import Redis -from app.config import CACHE_ENABLE, CACHE_REDIS_URL +from app.config import ( + CACHE_ENABLE, + CACHE_REDIS_DB, + CACHE_REDIS_HOST, + CACHE_REDIS_PASSWORD, + CACHE_REDIS_PORT, +) class Cache: def __init__(self): if CACHE_ENABLE: - self._redis: Redis = Redis.from_url(CACHE_REDIS_URL) + self._redis: Redis = Redis( + host=CACHE_REDIS_HOST, + port=CACHE_REDIS_PORT, + password=CACHE_REDIS_PASSWORD, + db=CACHE_REDIS_DB, + ) else: self._redis = None diff --git a/app/config/base.py b/app/config/base.py index f145864..bc90fdc 100644 --- a/app/config/base.py +++ b/app/config/base.py @@ -18,9 +18,15 @@ # Cache CACHE_ENABLE = getenv_or_action("CACHE_ENABLE", default="false").lower() == "true" if CACHE_ENABLE: - CACHE_REDIS_URL = getenv_or_action("CACHE_REDIS_URL", action="raise") + CACHE_REDIS_HOST = getenv_or_action("CACHE_REDIS_HOST", action="raise") + CACHE_REDIS_PORT = int(getenv_or_action("CACHE_REDIS_PORT", action="raise")) + CACHE_REDIS_PASSWORD = getenv_or_action("CACHE_REDIS_PASSWORD", action="raise") + CACHE_REDIS_DB = int(getenv_or_action("CACHE_REDIS_DB", action="raise")) else: - CACHE_REDIS_URL = None + CACHE_REDIS_HOST = None + CACHE_REDIS_PORT = None + CACHE_REDIS_PASSWORD = None + CACHE_REDIS_DB = None CACHE_DEFAULT_TIMEOUT = int(getenv_or_action("CACHE_DEFAULT_TIMEOUT", default="43200")) # 12 hours # Profiling