"""Commands to manage Redis.""" import asyncio import typer from pdp import config from pdp.connectors.redis_client import RedisConnector from pdp.constants.constants import CacheEntryType from pdp.fastapi.schemas.infra import BludgeonCacheRequest, BludgeonCacheResponse from pdp.logic.infra import cache_bludgeon as cache_bludgeon_logic cli: typer.Typer = typer.Typer( short_help="Commands to manage redis", no_args_is_help=True ) async def _cache_bludgeon(cache_entry_type: CacheEntryType) -> BludgeonCacheResponse: """Bludgeon cache entries by type.""" redis_connector = RedisConnector( config.REDIS_URL, use_redis_cache=config.CACHE_USE_REDIS, ) result = await cache_bludgeon_logic( bludgeon_cache_request=BludgeonCacheRequest( cache_entry_type=cache_entry_type, delete=True, ), redis_connector=redis_connector, ) return result @cli.command("cache_bludgeon", short_help="Bludgeon cache entries by type.") def cache_bludgeon(cache_entry_type: CacheEntryType) -> None: """CLI method to bludgeon cache entries by type.""" asyncio.run(_cache_bludgeon(cache_entry_type))