Metadata-Version: 2.5
Name: romeways-redis-queue
Version: 0.1.1
Summary: Redis / KeyDB list queue connector for romeways
Project-URL: homepage, https://github.com/CenturyBoys/romeways
Project-URL: repository, https://github.com/CenturyBoys/romeways
Author-email: Marco Sievers de Almeida Ximit Gaia <im.ximit@gmail.com>
License-Expression: Apache-2.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <4,>=3.11
Requires-Dist: redis<7,>=5
Description-Content-Type: text/markdown

# Romeways Redis / KeyDB

This is an extra package for romeways — for more details access the
[romeways](https://github.com/CenturyBoys/romeways) Github page.

This package uses [redis-py](https://pypi.org/project/redis/) and a **Redis list** as a FIFO
queue (`RPUSH` to send, `LPOP` to consume). [KeyDB](https://docs.keydb.dev/) is a drop-in Redis
replacement, so the same connector works against either. Requires a server with `LPOP key count`
support (Redis >= 6.2, KeyDB).

## Configs

### Queue

```python
from dataclasses import dataclass

from romeways import GenericQueueConfig


@dataclass(slots=True, frozen=True)
class RedisQueueConfig(GenericQueueConfig):
    """
    key: str Redis / KeyDB key — a list (mode="list") or a stream (mode="streams").
    mode: "list" | "streams" Backend data structure. Default "list".
    group / consumer: str Consumer group / consumer name (streams mode only).
    """

    key: str
    mode: str = "list"        # "list" or "streams"
    group: str = "romeways"   # streams only
    consumer: str = "romeways"  # streams only
    connector_name: str
    frequency: float
    max_chunk_size: int
    sequential: bool
    retries: int
```

### Connector

```python
from dataclasses import dataclass

from romeways import GenericConnectorConfig


@dataclass(slots=True, frozen=True)
class RedisConnectorConfig(GenericConnectorConfig):
    """
    url: str Redis / KeyDB connection URL, e.g. "redis://localhost:6379/0".
    """

    url: str = "redis://localhost:6379/0"
```

## Use case

```python
import asyncio

import romeways

# Create a queue config
config_q = romeways.RedisQueueConfig(
    key="queue.payment.done",
    connector_name="redis-dev1",
    frequency=1,
    max_chunk_size=10,
    sequential=False,
    retries=3,
)


# Register a controller/consumer for the queue name
@romeways.queue_consumer(queue_name="queue.payment.done", config=config_q)
async def controller(message: romeways.Message):
    print(message)


config_p = romeways.RedisConnectorConfig(
    connector_name="redis-dev1",
    url="redis://localhost:6379/0",
)

# Register a connector
romeways.connector_register(
    connector=romeways.RedisQueueConnector, config=config_p, spawn_process=False
)

asyncio.run(romeways.start())
```

## Backends (`mode`)

- **`list`** (default): a Redis list — producers `RPUSH` to the right, the consumer `LPOP key
  count`s from the left (FIFO, no acks). Requires Redis >= 6.2 / KeyDB.
- **`streams`**: a Redis stream with a consumer group — `XADD` to send, `XREADGROUP` + `XACK`
  to consume. Gives consumer groups and redelivery of unacked entries. Set `group`/`consumer`.

Both backends were tested against a real Redis server (throughput + resend).

## Notes
- romeways' own resend-on-error (`ResendException`) re-sends the message to the same key,
  honouring the queue's `retries`.
- Use `spawn_process=False`: the Redis connection is created in `on_start` on the running loop.
