romeways-redis-queue 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ from .config import RedisConnectorConfig, RedisQueueConfig
2
+ from .infrastructure import RedisQueueConnector
@@ -0,0 +1,2 @@
1
+ from .connector import RedisConnectorConfig
2
+ from .queue import RedisQueueConfig
@@ -0,0 +1 @@
1
+ from .model import RedisConnectorConfig
@@ -0,0 +1,13 @@
1
+ from dataclasses import dataclass
2
+
3
+ from romeways import GenericConnectorConfig
4
+
5
+
6
+ @dataclass(slots=True, frozen=True)
7
+ class RedisConnectorConfig(GenericConnectorConfig):
8
+ """
9
+ url: str Redis / KeyDB connection URL, e.g. "redis://localhost:6379/0".
10
+ See redis.asyncio.from_url -> https://redis.readthedocs.io/
11
+ """
12
+
13
+ url: str = "redis://localhost:6379/0"
@@ -0,0 +1 @@
1
+ from .model import RedisQueueConfig
@@ -0,0 +1,12 @@
1
+ from dataclasses import dataclass
2
+
3
+ from romeways import GenericQueueConfig
4
+
5
+
6
+ @dataclass(slots=True, frozen=True)
7
+ class RedisQueueConfig(GenericQueueConfig):
8
+ """
9
+ key: str Redis / KeyDB list key used as the queue (RPUSH to send, LPOP to consume).
10
+ """
11
+
12
+ key: str
@@ -0,0 +1 @@
1
+ from .connector import RedisQueueConnector
@@ -0,0 +1 @@
1
+ from .infrastructure import RedisQueueConnector
@@ -0,0 +1,38 @@
1
+ import logging
2
+
3
+ from redis.asyncio import Redis, from_url
4
+
5
+ from romeways import AQueueConnector
6
+
7
+ from romeways_redis_queue.config import RedisConnectorConfig, RedisQueueConfig
8
+
9
+ logger = logging.getLogger("romeways")
10
+
11
+
12
+ class RedisQueueConnector(AQueueConnector):
13
+ """romeways connector backed by a Redis / KeyDB list (FIFO).
14
+
15
+ Messages are ``RPUSH``ed to the list and ``LPOP``ped in batches. KeyDB is a
16
+ drop-in Redis replacement, so this works against either. romeways' own
17
+ resend-on-error (``ResendException``) re-pushes the message to the same list.
18
+
19
+ Requires a server with ``LPOP key count`` support (Redis >= 6.2, KeyDB).
20
+ """
21
+
22
+ _connector_config: RedisConnectorConfig
23
+ _config: RedisQueueConfig
24
+
25
+ async def on_start(self):
26
+ self._redis: Redis = from_url(self._connector_config.url)
27
+
28
+ async def get_messages(self, max_chunk_size: int) -> list[bytes]:
29
+ items = await self._redis.lpop(self._config.key, abs(max_chunk_size))
30
+ if not items:
31
+ return []
32
+ # With a count, LPOP returns a list; guard the single-value form just in case.
33
+ if isinstance(items, (bytes, bytearray, str)):
34
+ return [items if isinstance(items, bytes) else bytes(items)]
35
+ return list(items)
36
+
37
+ async def send_messages(self, message: bytes):
38
+ await self._redis.rpush(self._config.key, message)
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.5
2
+ Name: romeways-redis-queue
3
+ Version: 0.1.0
4
+ Summary: Redis / KeyDB list queue connector for romeways
5
+ Project-URL: homepage, https://github.com/CenturyBoys/romeways
6
+ Project-URL: repository, https://github.com/CenturyBoys/romeways
7
+ Author-email: Marco Sievers de Almeida Ximit Gaia <im.ximit@gmail.com>
8
+ License-Expression: Apache-2.0
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Python: <4,>=3.11
15
+ Requires-Dist: redis<7,>=5
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Romeways Redis / KeyDB
19
+
20
+ This is an extra package for romeways — for more details access the
21
+ [romeways](https://github.com/CenturyBoys/romeways) Github page.
22
+
23
+ This package uses [redis-py](https://pypi.org/project/redis/) and a **Redis list** as a FIFO
24
+ queue (`RPUSH` to send, `LPOP` to consume). [KeyDB](https://docs.keydb.dev/) is a drop-in Redis
25
+ replacement, so the same connector works against either. Requires a server with `LPOP key count`
26
+ support (Redis >= 6.2, KeyDB).
27
+
28
+ ## Configs
29
+
30
+ ### Queue
31
+
32
+ ```python
33
+ from dataclasses import dataclass
34
+
35
+ from romeways import GenericQueueConfig
36
+
37
+
38
+ @dataclass(slots=True, frozen=True)
39
+ class RedisQueueConfig(GenericQueueConfig):
40
+ """
41
+ key: str Redis / KeyDB list key used as the queue.
42
+ """
43
+
44
+ key: str
45
+ connector_name: str
46
+ frequency: float
47
+ max_chunk_size: int
48
+ sequential: bool
49
+ retries: int
50
+ ```
51
+
52
+ ### Connector
53
+
54
+ ```python
55
+ from dataclasses import dataclass
56
+
57
+ from romeways import GenericConnectorConfig
58
+
59
+
60
+ @dataclass(slots=True, frozen=True)
61
+ class RedisConnectorConfig(GenericConnectorConfig):
62
+ """
63
+ url: str Redis / KeyDB connection URL, e.g. "redis://localhost:6379/0".
64
+ """
65
+
66
+ url: str = "redis://localhost:6379/0"
67
+ ```
68
+
69
+ ## Use case
70
+
71
+ ```python
72
+ import asyncio
73
+
74
+ import romeways
75
+
76
+ # Create a queue config
77
+ config_q = romeways.RedisQueueConfig(
78
+ key="queue.payment.done",
79
+ connector_name="redis-dev1",
80
+ frequency=1,
81
+ max_chunk_size=10,
82
+ sequential=False,
83
+ retries=3,
84
+ )
85
+
86
+
87
+ # Register a controller/consumer for the queue name
88
+ @romeways.queue_consumer(queue_name="queue.payment.done", config=config_q)
89
+ async def controller(message: romeways.Message):
90
+ print(message)
91
+
92
+
93
+ config_p = romeways.RedisConnectorConfig(
94
+ connector_name="redis-dev1",
95
+ url="redis://localhost:6379/0",
96
+ )
97
+
98
+ # Register a connector
99
+ romeways.connector_register(
100
+ connector=romeways.RedisQueueConnector, config=config_p, spawn_process=False
101
+ )
102
+
103
+ asyncio.run(romeways.start())
104
+ ```
105
+
106
+ ## Semantics
107
+
108
+ - A Redis **list** is the queue: producers `RPUSH` to the right, the consumer `LPOP`s from the
109
+ left — FIFO.
110
+ - `get_messages` pops up to `max_chunk_size` items in one `LPOP key count` call.
111
+ - There are no consumer groups / acks (that would be Redis Streams); romeways' own
112
+ resend-on-error (`ResendException`) re-pushes the message to the same list, honouring the
113
+ queue's `retries`.
114
+ - Use `spawn_process=False`: the Redis connection is created in `on_start` on the running loop.
@@ -0,0 +1,12 @@
1
+ romeways_redis_queue/__init__.py,sha256=qu6ugqxKc3TMGyqicG1fL62pT4QG8LkGxlnrML5y3-s,107
2
+ romeways_redis_queue/config/__init__.py,sha256=rBrbhzxnVFKRN59W0L63XTH8zb4FG2wMBUwobyG87YA,80
3
+ romeways_redis_queue/config/connector/__init__.py,sha256=83xMBPJGppmE5m96xV8tmJMVti2TJ_fry4TZwILSRlw,40
4
+ romeways_redis_queue/config/connector/model.py,sha256=9jAv7gu8tDvRThNGQPKPtm2DGGUGpZXF4x6j4b5lT6U,369
5
+ romeways_redis_queue/config/queue/__init__.py,sha256=uN2UCLanqGaemHJiGIPpVNavd4Sv8Tay351Bi5Cvsgs,36
6
+ romeways_redis_queue/config/queue/model.py,sha256=OEEIuf6QmyMWL9d7lNyCH3-NlCqI-9415bVz-nPkbJs,275
7
+ romeways_redis_queue/infrastructure/__init__.py,sha256=w9POYh5P3RaA-zwyHH8fDQTJ3jqpmpS3HFNmNA3mYUI,43
8
+ romeways_redis_queue/infrastructure/connector/__init__.py,sha256=DqSBX6wOV2dsI1RuDWfNFJVKkVg5TBYdm6IwzbCDIz8,48
9
+ romeways_redis_queue/infrastructure/connector/infrastructure.py,sha256=BSwvS9DqiabTihuYlKPC3nLD0Lwskoufsk12Ke5t504,1369
10
+ romeways_redis_queue-0.1.0.dist-info/METADATA,sha256=sqg7CKF49ocx9z6fg2I-70nJaPksL_kCgpoxwsf2sfo,3142
11
+ romeways_redis_queue-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
12
+ romeways_redis_queue-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any