Repository: taskiq-python/taskiq-redis

Issue:
Url cannot be Optional
`BaseRedisBroker` always expects url for redis. However, for some reasons now it's set to None by default. Later `BaseRedisBroker` uses this `Optional[str]` in Redis ConnectionPool. ConnectionPool expects a `str` (not `Optional[str]`). This can be unclear [from documentation][redis] but I checked: it fails.

```plain
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "hidden/virtualenvs/parla-JNkILVkS-py3.10/lib/python3.10/site-packages/taskiq_redis/redis_broker.py", line 41, in __init__
    self.connection_pool: ConnectionPool = ConnectionPool.from_url(
  File "hidden/virtualenvs/parla-JNkILVkS-py3.10/lib/python3.10/site-packages/redis/asyncio/connection.py", line 1259, in from_url
    url_options = parse_url(url)
  File "hidden/virtualenvs/parla-JNkILVkS-py3.10/lib/python3.10/site-packages/redis/asyncio/connection.py", line 1195, in parse_url
    raise ValueError(
ValueError: Redis URL must specify one of the following schemes (redis://, rediss://, unix://)
```

How did I find out this? I messed up with a parameter name and tried to create a broker by `ListQueueBroker(redis_url="redis://localhost/0")` instead of `ListQueueBroker(url="redis://localhost/0")`. It was fun to debug.

# TL;DR: What to do?
Make this:

```python
class BaseRedisBroker(AsyncBroker):
    """Base broker that works with Redis."""

    def __init__(
        self,
        url: str,  # <--
    # ...
```

[redis]: https://redis-py.readthedocs.io/en/stable/connections.html#redis.connection.ConnectionPool.from_url

Hints from issue comments:
@igoose1: Closing as #40 was merged.

Solution patch:
diff --git a/taskiq_redis/redis_broker.py b/taskiq_redis/redis_broker.py
index 7253fb6..eaf309b 100644
--- a/taskiq_redis/redis_broker.py
+++ b/taskiq_redis/redis_broker.py
@@ -16,7 +16,7 @@ class BaseRedisBroker(AsyncBroker):
 
     def __init__(
         self,
-        url: Optional[str] = None,
+        url: str,
         task_id_generator: Optional[Callable[[], str]] = None,
         result_backend: Optional[AsyncResultBackend[_T]] = None,
         queue_name: str = "taskiq",


Test patch:
diff --git a/tests/test_broker.py b/tests/test_broker.py
index 62a9779..af731bd 100644
--- a/tests/test_broker.py
+++ b/tests/test_broker.py
@@ -8,6 +8,12 @@ from taskiq import AckableMessage, AsyncBroker, BrokerMessage
 from taskiq_redis import ListQueueBroker, PubSubBroker
 
 
+def test_no_url_should_raise_typeerror() -> None:
+    """Test that url is expected."""
+    with pytest.raises(TypeError):
+        ListQueueBroker()  # type: ignore
+
+
 async def get_message(  # type: ignore
     broker: AsyncBroker,
 ) -> Union[bytes, AckableMessage]: