def METHOD_NAME(key: str, attempts: int, window: int) -> bool:
    """Generic rate limit helper."""
    # Initialize the bucket (atomically on redis)
    if not IS_USING_REDIS:
        if cache.get(key) is None:
            cache.set(key, attempts, window)
    else:
        cache.set(key, attempts, window, nx=True)
    try:
        # Count current event
        cache.decr(key)
    except ValueError:
        current = 0
    else:
        # Get remaining bucket
        current = cache.get(key, 0)
    return current < 0