Compare commits
No commits in common. "39a90d39fd8a88bc47eb87ed58e4a7c10062deab" and "d19a7381f31d13cecc94838dabe839fc9d86e393" have entirely different histories.
39a90d39fd
...
d19a7381f3
@ -5,7 +5,7 @@ from libbot.pycord.classes import PycordBot
|
|||||||
|
|
||||||
from classes.cache.holo_cache_memcached import HoloCacheMemcached
|
from classes.cache.holo_cache_memcached import HoloCacheMemcached
|
||||||
from classes.cache.holo_cache_redis import HoloCacheRedis
|
from classes.cache.holo_cache_redis import HoloCacheRedis
|
||||||
from modules.cache_manager import create_cache_client
|
from modules.cache_utils import create_cache_client
|
||||||
|
|
||||||
logger: Logger = logging.getLogger(__name__)
|
logger: Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
from typing import Dict, Any, Literal
|
|
||||||
|
|
||||||
from classes.cache.holo_cache_memcached import HoloCacheMemcached
|
|
||||||
from classes.cache.holo_cache_redis import HoloCacheRedis
|
|
||||||
|
|
||||||
|
|
||||||
def create_cache_client(
|
|
||||||
config: Dict[str, Any],
|
|
||||||
engine: Literal["memcached", "redis"] | None = None,
|
|
||||||
) -> HoloCacheMemcached | HoloCacheRedis:
|
|
||||||
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 HoloCacheMemcached.from_config(config["cache"][engine])
|
|
||||||
case "redis":
|
|
||||||
return HoloCacheRedis.from_config(config["cache"][engine])
|
|
||||||
case _:
|
|
||||||
raise KeyError(
|
|
||||||
f"Cache implementation for the engine '{engine}' is not present."
|
|
||||||
)
|
|
@ -1,9 +1,37 @@
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from typing import Any
|
from typing import Dict, Any, Literal
|
||||||
|
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
from ujson import dumps, loads
|
from ujson import dumps, loads
|
||||||
|
|
||||||
|
from classes.cache.holo_cache_memcached import HoloCacheMemcached
|
||||||
|
from classes.cache.holo_cache_redis import HoloCacheRedis
|
||||||
|
|
||||||
|
|
||||||
|
def create_cache_client(
|
||||||
|
config: Dict[str, Any],
|
||||||
|
engine: Literal["memcached", "redis"] | None = None,
|
||||||
|
) -> HoloCacheMemcached | HoloCacheRedis:
|
||||||
|
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 HoloCacheMemcached.from_config(config["cache"][engine])
|
||||||
|
case "redis":
|
||||||
|
return HoloCacheRedis.from_config(config["cache"][engine])
|
||||||
|
case _:
|
||||||
|
raise KeyError(
|
||||||
|
f"Cache implementation for the engine '{engine}' is not present."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def json_to_string(json_object: Any) -> str:
|
def json_to_string(json_object: Any) -> str:
|
||||||
json_object_copy: Any = deepcopy(json_object)
|
json_object_copy: Any = deepcopy(json_object)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user