Skip to content

Commit

Permalink
chore: split redis envs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-milan committed Oct 30, 2023
1 parent 7c42cc0 commit f90b535
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 13 additions & 2 deletions app/cache.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 8 additions & 2 deletions app/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f90b535

Please sign in to comment.