Hopefully fixed a circular import
All checks were successful
Analysis / SonarCloud (push) Successful in 47s
All checks were successful
Analysis / SonarCloud (push) Successful in 47s
This commit is contained in:
1
src/libbot/cache/utils/__init__.py
vendored
1
src/libbot/cache/utils/__init__.py
vendored
@@ -1 +0,0 @@
|
||||
from .manager import create_cache_client
|
||||
|
24
src/libbot/cache/utils/manager.py
vendored
24
src/libbot/cache/utils/manager.py
vendored
@@ -1,24 +0,0 @@
|
||||
from typing import Dict, Any, Literal
|
||||
|
||||
from ..classes import CacheMemcached, CacheRedis
|
||||
|
||||
|
||||
def create_cache_client(
|
||||
config: Dict[str, Any],
|
||||
engine: Literal["memcached", "redis"] | None = None,
|
||||
) -> CacheMemcached | CacheRedis:
|
||||
if engine not in ["memcached", "redis"] or engine is None:
|
||||
raise KeyError(f"Incorrect cache engine provided. Expected 'memcached' or 'redis', got '{engine}'")
|
||||
|
||||
if "cache" not in config or engine not in config["cache"]:
|
||||
raise KeyError(
|
||||
f"Cache configuration is invalid. Please check if all keys are set (engine: '{engine}')"
|
||||
)
|
||||
|
||||
match engine:
|
||||
case "memcached":
|
||||
return CacheMemcached.from_config(config["cache"][engine])
|
||||
case "redis":
|
||||
return CacheRedis.from_config(config["cache"][engine])
|
||||
case _:
|
||||
raise KeyError(f"Cache implementation for the engine '{engine}' is not present.")
|
Reference in New Issue
Block a user