Skip to content

Commit

Permalink
feat: add get_default_redis_url() (#610)
Browse files Browse the repository at this point in the history
Co-authored-by: Holger Stitz <[email protected]>
  • Loading branch information
dvviktordelev and thinkh authored Nov 5, 2024
1 parent fead1c4 commit bf95ceb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions visyn_core/settings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,23 @@ def get_default_postgres_url(
Returns a default postgres url, including the default values for `driver`, `user`, `password`, `host`, `port` and `database`.
"""
return f"{driver}://{user}:{password}@{host or host_fallback}:{port or port_fallback}/{database}"


def get_default_redis_url(
*,
host: str | None = os.getenv("REDIS_HOSTNAME"),
host_fallback: str = "localhost",
port: int | str | None = os.getenv("REDIS_PORT"),
port_fallback: int = 6379,
db: int = 1,
timeout: int = 60 * 60 * 24,
) -> dict:
"""
Returns a default Redis configuration dictionary with `host`, `port`, `db`, and `timeout`.
"""
return {
"host": host or host_fallback,
"port": int(port) if port else port_fallback,
"db": db,
"timeout": timeout,
}

0 comments on commit bf95ceb

Please sign in to comment.