redqueue 0.10.0__tar.gz

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.
Files changed (36) hide show
  1. redqueue-0.10.0/.github/workflows/ci.yml +52 -0
  2. redqueue-0.10.0/.gitignore +13 -0
  3. redqueue-0.10.0/CHANGELOG.md +70 -0
  4. redqueue-0.10.0/LICENSE +158 -0
  5. redqueue-0.10.0/NOTICE +4 -0
  6. redqueue-0.10.0/PKG-INFO +312 -0
  7. redqueue-0.10.0/README.md +279 -0
  8. redqueue-0.10.0/docs/API.md +249 -0
  9. redqueue-0.10.0/docs/RELEASE.md +131 -0
  10. redqueue-0.10.0/pyproject.toml +72 -0
  11. redqueue-0.10.0/requirements.txt +24 -0
  12. redqueue-0.10.0/scripts/check.py +27 -0
  13. redqueue-0.10.0/src/redqueue/__init__.py +72 -0
  14. redqueue-0.10.0/src/redqueue/_version.py +6 -0
  15. redqueue-0.10.0/src/redqueue/async_client.py +194 -0
  16. redqueue-0.10.0/src/redqueue/backends/__init__.py +20 -0
  17. redqueue-0.10.0/src/redqueue/backends/async_delay.py +242 -0
  18. redqueue-0.10.0/src/redqueue/backends/async_list.py +308 -0
  19. redqueue-0.10.0/src/redqueue/backends/async_stream.py +394 -0
  20. redqueue-0.10.0/src/redqueue/backends/base.py +103 -0
  21. redqueue-0.10.0/src/redqueue/backends/delay.py +243 -0
  22. redqueue-0.10.0/src/redqueue/backends/list.py +303 -0
  23. redqueue-0.10.0/src/redqueue/backends/stream.py +370 -0
  24. redqueue-0.10.0/src/redqueue/client.py +168 -0
  25. redqueue-0.10.0/src/redqueue/compat.py +184 -0
  26. redqueue-0.10.0/src/redqueue/config.py +155 -0
  27. redqueue-0.10.0/src/redqueue/exceptions.py +167 -0
  28. redqueue-0.10.0/src/redqueue/message.py +67 -0
  29. redqueue-0.10.0/src/redqueue/monitoring.py +112 -0
  30. redqueue-0.10.0/src/redqueue/serialization.py +79 -0
  31. redqueue-0.10.0/tests/README.md +22 -0
  32. redqueue-0.10.0/tests/__init__.py +4 -0
  33. redqueue-0.10.0/tests/fakes.py +362 -0
  34. redqueue-0.10.0/tests/test_backend_contracts.py +76 -0
  35. redqueue-0.10.0/tests/test_integration_redis.py +41 -0
  36. redqueue-0.10.0/tests/test_project_skeleton.py +755 -0
@@ -0,0 +1,52 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ quality:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
15
+ services:
16
+ redis:
17
+ image: redis:7
18
+ ports:
19
+ - 6379:6379
20
+ options: >-
21
+ --health-cmd "redis-cli ping"
22
+ --health-interval 10s
23
+ --health-timeout 5s
24
+ --health-retries 5
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+ - uses: actions/setup-python@v5
28
+ with:
29
+ python-version: ${{ matrix.python-version }}
30
+ - name: Install dependencies
31
+ run: python -m pip install -r requirements.txt
32
+ - name: Ruff
33
+ run: python -m ruff check .
34
+ - name: Mypy
35
+ run: python -m mypy
36
+ - name: Tests
37
+ env:
38
+ PYTHONPATH: src
39
+ REDQUEUE_REDIS_URL: redis://localhost:6379/0
40
+ run: python -m pytest
41
+
42
+ python39-compat:
43
+ runs-on: ubuntu-latest
44
+ steps:
45
+ - uses: actions/checkout@v4
46
+ - uses: actions/setup-python@v5
47
+ with:
48
+ python-version: "3.9"
49
+ - name: Install runtime package
50
+ run: python -m pip install -e .
51
+ - name: Compile source on Python 3.9
52
+ run: python -m compileall src scripts
@@ -0,0 +1,13 @@
1
+ docs/dev/
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .pytest_cache/
6
+ .mypy_cache/
7
+ .ruff_cache/
8
+ .coverage
9
+ htmlcov/
10
+ dist/
11
+ build/
12
+ .venv/
13
+ venv/
@@ -0,0 +1,70 @@
1
+ # Changelog / 版本变更记录
2
+
3
+ All notable public release changes are documented here.
4
+
5
+ 所有公开发布版本的重要变更都会记录在此文件中。
6
+
7
+ Development versions are tracked separately from formal release versions.
8
+ 开发版本与正式版本分开管理。
9
+
10
+ ## [0.10.0] - 2026-06-20
11
+
12
+ ### Added
13
+
14
+ - Initial public release of RedQueue.
15
+ - Synchronous `QueueClient` and asynchronous `AsyncQueueClient`.
16
+ - Redis List backend with reliable processing, ack, nack, retry, recovery, and
17
+ dead-letter support.
18
+ - Redis Streams backend with consumer groups, ack, retry, dead-letter support,
19
+ and pending recovery.
20
+ - Delayed tasks based on Redis Sorted Set.
21
+ - Redis version and capability detection through `INFO server`.
22
+ - Unified exception hierarchy with structured context.
23
+ - JSON serializer and custom serializer protocol.
24
+ - Monitoring hook system with safe wrapper, in-memory hook, and composite hook.
25
+ - Unit, contract, asynchronous, and opt-in Redis integration tests.
26
+ - GitHub Actions CI and local quality check script.
27
+
28
+ ### 新增
29
+
30
+ - RedQueue 首个公开发布版本。
31
+ - 同步 `QueueClient` 与异步 `AsyncQueueClient`。
32
+ - Redis List 后端,支持可靠处理、ack、nack、retry、恢复和死信。
33
+ - Redis Streams 后端,支持消费组、ack、retry、死信和 pending 恢复。
34
+ - 基于 Redis Sorted Set 的延迟任务。
35
+ - 通过 `INFO server` 进行 Redis 版本与能力探测。
36
+ - 带结构化上下文的统一异常体系。
37
+ - JSON 序列化器与自定义序列化协议。
38
+ - 监控 hook 系统,包含安全包装、内存 hook 和组合 hook。
39
+ - 单元测试、契约测试、异步测试和可选 Redis 集成测试。
40
+ - GitHub Actions CI 与本地质量检查脚本。
41
+
42
+ ### Compatibility
43
+
44
+ - Python `>=3.9`.
45
+ - Runtime dependency `redis==6.4.0`.
46
+ - Redis Streams require Redis `>=5.0`.
47
+ - Redis Streams `XAUTOCLAIM` and List `BLMOVE` are used when Redis `>=6.2`.
48
+ - Delayed tasks use Redis Sorted Set.
49
+
50
+ ### 兼容性
51
+
52
+ - Python `>=3.9`。
53
+ - 运行依赖 `redis==6.4.0`。
54
+ - Redis Streams 要求 Redis `>=5.0`。
55
+ - Redis `>=6.2` 时使用 Streams `XAUTOCLAIM` 与 List `BLMOVE`。
56
+ - 延迟任务使用 Redis Sorted Set。
57
+
58
+ ### Validation
59
+
60
+ - `python -m ruff check .`
61
+ - `PYTHONPATH=src python -m mypy`
62
+ - `PYTHONPATH=src python -m pytest`
63
+ - `REDQUEUE_REDIS_URL=redis://127.0.0.1:6379/0 PYTHONPATH=src python -m pytest -m integration`
64
+
65
+ ### 验证
66
+
67
+ - `python -m ruff check .`
68
+ - `PYTHONPATH=src python -m mypy`
69
+ - `PYTHONPATH=src python -m pytest`
70
+ - `REDQUEUE_REDIS_URL=redis://127.0.0.1:6379/0 PYTHONPATH=src python -m pytest -m integration`
@@ -0,0 +1,158 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work.
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+ by the copyright owner or by an individual or Legal Entity authorized to submit
48
+ on behalf of the copyright owner. For the purposes of this definition,
49
+ "submitted" means any form of electronic, verbal, or written communication sent
50
+ to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and
52
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+ the purpose of discussing and improving the Work, but excluding communication
54
+ that is conspicuously marked or otherwise designated in writing by the copyright
55
+ owner as "Not a Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
62
+ License, each Contributor hereby grants to You a perpetual, worldwide,
63
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
64
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
65
+ sublicense, and distribute the Work and such Derivative Works in Source or
66
+ Object form.
67
+
68
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
69
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
70
+ no-charge, royalty-free, irrevocable patent license to make, have made, use,
71
+ offer to sell, sell, import, and otherwise transfer the Work, where such license
72
+ applies only to those patent claims licensable by such Contributor that are
73
+ necessarily infringed by their Contribution(s) alone or by combination of their
74
+ Contribution(s) with the Work to which such Contribution(s) was submitted. If
75
+ You institute patent litigation against any entity (including a cross-claim or
76
+ counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated
77
+ within the Work constitutes direct or contributory patent infringement, then any
78
+ patent licenses granted to You under this License for that Work shall terminate
79
+ as of the date such litigation is filed.
80
+
81
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
82
+ Derivative Works thereof in any medium, with or without modifications, and in
83
+ Source or Object form, provided that You meet the following conditions:
84
+
85
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
86
+ this License; and
87
+
88
+ (b) You must cause any modified files to carry prominent notices stating that You
89
+ changed the files; and
90
+
91
+ (c) You must retain, in the Source form of any Derivative Works that You
92
+ distribute, all copyright, patent, trademark, and attribution notices from the
93
+ Source form of the Work, excluding those notices that do not pertain to any part
94
+ of the Derivative Works; and
95
+
96
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
97
+ any Derivative Works that You distribute must include a readable copy of the
98
+ attribution notices contained within such NOTICE file, excluding those notices
99
+ that do not pertain to any part of the Derivative Works, in at least one of the
100
+ following places: within a NOTICE text file distributed as part of the
101
+ Derivative Works; within the Source form or documentation, if provided along
102
+ with the Derivative Works; or, within a display generated by the Derivative
103
+ Works, if and wherever such third-party notices normally appear. The contents of
104
+ the NOTICE file are for informational purposes only and do not modify the
105
+ License. You may add Your own attribution notices within Derivative Works that
106
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
107
+ provided that such additional attribution notices cannot be construed as
108
+ modifying the License.
109
+
110
+ You may add Your own copyright statement to Your modifications and may provide
111
+ additional or different license terms and conditions for use, reproduction, or
112
+ distribution of Your modifications, or for any such Derivative Works as a whole,
113
+ provided Your use, reproduction, and distribution of the Work otherwise complies
114
+ with the conditions stated in this License.
115
+
116
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
117
+ Contribution intentionally submitted for inclusion in the Work by You to the
118
+ Licensor shall be under the terms and conditions of this License, without any
119
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
120
+ supersede or modify the terms of any separate license agreement you may have
121
+ executed with Licensor regarding such Contributions.
122
+
123
+ 6. Trademarks. This License does not grant permission to use the trade names,
124
+ trademarks, service marks, or product names of the Licensor, except as required
125
+ for reasonable and customary use in describing the origin of the Work and
126
+ reproducing the content of the NOTICE file.
127
+
128
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
129
+ writing, Licensor provides the Work (and each Contributor provides its
130
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
131
+ KIND, either express or implied, including, without limitation, any warranties or
132
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
133
+ PARTICULAR PURPOSE. You are solely responsible for determining the
134
+ appropriateness of using or redistributing the Work and assume any risks
135
+ associated with Your exercise of permissions under this License.
136
+
137
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
138
+ tort (including negligence), contract, or otherwise, unless required by
139
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
140
+ writing, shall any Contributor be liable to You for damages, including any
141
+ direct, indirect, special, incidental, or consequential damages of any character
142
+ arising as a result of this License or out of the use or inability to use the
143
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
144
+ computer failure or malfunction, or any and all other commercial damages or
145
+ losses), even if such Contributor has been advised of the possibility of such
146
+ damages.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
149
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
150
+ acceptance of support, warranty, indemnity, or other liability obligations
151
+ and/or rights consistent with this License. However, in accepting such
152
+ obligations, You may act only on Your own behalf and on Your sole
153
+ responsibility, not on behalf of any other Contributor, and only if You agree to
154
+ indemnify, defend, and hold each Contributor harmless for any liability incurred
155
+ by, or claims asserted against, such Contributor by reason of your accepting any
156
+ such warranty or additional liability.
157
+
158
+ END OF TERMS AND CONDITIONS
redqueue-0.10.0/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ RedQueue
2
+ Copyright 2026 SpringMirror-pear
3
+
4
+ This product is licensed under the Apache License, Version 2.0.
@@ -0,0 +1,312 @@
1
+ Metadata-Version: 2.4
2
+ Name: redqueue
3
+ Version: 0.10.0
4
+ Summary: Redis-backed Python message queue library with List, Streams, delayed tasks, and monitoring.
5
+ Project-URL: Homepage, https://github.com/SpringMirror-pear/redqueue
6
+ Project-URL: Repository, https://github.com/SpringMirror-pear/redqueue.git
7
+ Project-URL: Issues, https://github.com/SpringMirror-pear/redqueue/issues
8
+ Author: SpringMirror-pear
9
+ Maintainer: SpringMirror-pear
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: delayed-jobs,message-queue,queue,redis,streams
14
+ Classifier: Development Status :: 2 - Pre-Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Requires-Python: >=3.9
26
+ Requires-Dist: redis==6.4.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: mypy==2.1.0; (python_version >= '3.10') and extra == 'dev'
29
+ Requires-Dist: pytest-asyncio==1.4.0; (python_version >= '3.10') and extra == 'dev'
30
+ Requires-Dist: pytest==9.1.1; (python_version >= '3.10') and extra == 'dev'
31
+ Requires-Dist: ruff==0.15.18; extra == 'dev'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # RedQueue
35
+
36
+ RedQueue is a Redis-backed Python message queue library with List, Streams,
37
+ delayed tasks, synchronous APIs, asynchronous APIs, compatibility checks, and
38
+ monitoring hooks.
39
+
40
+ RedQueue 是一个基于 Redis 的 Python 消息队列库,支持 List、Streams、延迟任务、
41
+ 同步 API、异步 API、兼容性检查和监控 hook。
42
+
43
+ Repository / 仓库:
44
+ https://github.com/SpringMirror-pear/redqueue.git
45
+
46
+ ## Features / 功能
47
+
48
+ - Redis List reliable queue with `BLMOVE` on Redis `>=6.2` and `BRPOPLPUSH`
49
+ fallback on older compatible Redis versions.
50
+ - Redis Streams backend with consumer groups. Streams require Redis `>=5.0`.
51
+ - Delayed tasks based on Redis Sorted Set.
52
+ - Sync client `QueueClient` and async client `AsyncQueueClient`.
53
+ - Unified exception hierarchy with structured context.
54
+ - Monitoring events for publish, consume, ack, nack, retry, dead letter, delay,
55
+ and backend errors.
56
+ - Redis capability detection from `INFO server`.
57
+ - Apache License 2.0.
58
+
59
+ - 基于 Redis List 的可靠队列:Redis `>=6.2` 使用 `BLMOVE`,低版本兼容时回退
60
+ `BRPOPLPUSH`。
61
+ - 基于 Redis Streams 的消费组后端,Streams 要求 Redis `>=5.0`。
62
+ - 基于 Redis Sorted Set 的延迟任务。
63
+ - 同步客户端 `QueueClient` 与异步客户端 `AsyncQueueClient`。
64
+ - 带结构化上下文的统一异常体系。
65
+ - 针对发布、消费、确认、拒绝、重试、死信、延迟和后端错误的监控事件。
66
+ - 通过 `INFO server` 探测 Redis 能力。
67
+ - Apache License 2.0。
68
+
69
+ ## Compatibility / 兼容性
70
+
71
+ Runtime:
72
+
73
+ - Python `>=3.9`
74
+ - redis-py `6.4.0`
75
+ - Target development environment: Python `3.14.5`
76
+
77
+ Redis:
78
+
79
+ | Feature | Redis requirement | Notes |
80
+ | --- | --- | --- |
81
+ | List blocking consume | `>=2.0` | Uses `BLPOP` family compatibility baseline |
82
+ | List reliable move | `>=2.2` | Uses `BRPOPLPUSH`; `BLMOVE` preferred on `>=6.2` |
83
+ | Streams | `>=5.0` | Uses `XADD`, `XGROUP CREATE`, `XREADGROUP` |
84
+ | Streams auto claim | `>=6.2` | Uses `XAUTOCLAIM`; Redis 5.x uses `XPENDING`/`XCLAIM` fallback |
85
+ | Delayed tasks | `>=1.2` | Uses `ZADD` and timestamp scores |
86
+
87
+ 运行环境:
88
+
89
+ - Python `>=3.9`
90
+ - redis-py `6.4.0`
91
+ - 目标开发环境:Python `3.14.5`
92
+
93
+ Redis:
94
+
95
+ | 功能 | Redis 要求 | 说明 |
96
+ | --- | --- | --- |
97
+ | List 阻塞消费 | `>=2.0` | 以 `BLPOP` 系列能力为基础 |
98
+ | List 可靠搬移 | `>=2.2` | 使用 `BRPOPLPUSH`;Redis `>=6.2` 优先使用 `BLMOVE` |
99
+ | Streams | `>=5.0` | 使用 `XADD`、`XGROUP CREATE`、`XREADGROUP` |
100
+ | Streams 自动认领 | `>=6.2` | 使用 `XAUTOCLAIM`;Redis 5.x 回退 `XPENDING`/`XCLAIM` |
101
+ | 延迟任务 | `>=1.2` | 使用 `ZADD` 和时间戳 score |
102
+
103
+ ## Installation / 安装
104
+
105
+ ```bash
106
+ pip install redqueue
107
+ ```
108
+
109
+ For local development:
110
+
111
+ ```bash
112
+ python -m pip install -r requirements.txt
113
+ ```
114
+
115
+ 本地开发:
116
+
117
+ ```bash
118
+ python -m pip install -r requirements.txt
119
+ ```
120
+
121
+ ## Quick Start / 快速开始
122
+
123
+ Synchronous List queue:
124
+
125
+ ```python
126
+ from redqueue import QueueClient
127
+
128
+ client = QueueClient.from_url(
129
+ "redis://127.0.0.1:6379/0",
130
+ queue="emails",
131
+ backend="list",
132
+ )
133
+
134
+ message_id = client.publish({"to": "user@example.com"})
135
+ message = client.consume(timeout=1)
136
+
137
+ if message is not None:
138
+ try:
139
+ print(message.payload)
140
+ client.ack(message)
141
+ except Exception:
142
+ client.retry(message, reason="handler failed")
143
+ ```
144
+
145
+ 同步 List 队列:
146
+
147
+ ```python
148
+ from redqueue import QueueClient
149
+
150
+ client = QueueClient.from_url(
151
+ "redis://127.0.0.1:6379/0",
152
+ queue="emails",
153
+ backend="list",
154
+ )
155
+
156
+ message_id = client.publish({"to": "user@example.com"})
157
+ message = client.consume(timeout=1)
158
+
159
+ if message is not None:
160
+ try:
161
+ print(message.payload)
162
+ client.ack(message)
163
+ except Exception:
164
+ client.retry(message, reason="handler failed")
165
+ ```
166
+
167
+ Streams backend:
168
+
169
+ ```python
170
+ from redqueue import QueueClient
171
+
172
+ client = QueueClient.from_url(
173
+ "redis://127.0.0.1:6379/0",
174
+ queue="events",
175
+ backend="stream",
176
+ consumer_group="redqueue",
177
+ consumer_name="worker-1",
178
+ )
179
+
180
+ client.publish({"event": "created"})
181
+ message = client.consume(timeout=1)
182
+ ```
183
+
184
+ Streams 后端:
185
+
186
+ ```python
187
+ from redqueue import QueueClient
188
+
189
+ client = QueueClient.from_url(
190
+ "redis://127.0.0.1:6379/0",
191
+ queue="events",
192
+ backend="stream",
193
+ consumer_group="redqueue",
194
+ consumer_name="worker-1",
195
+ )
196
+
197
+ client.publish({"event": "created"})
198
+ message = client.consume(timeout=1)
199
+ ```
200
+
201
+ Asynchronous client:
202
+
203
+ ```python
204
+ import asyncio
205
+
206
+ from redqueue import AsyncQueueClient
207
+
208
+
209
+ async def main() -> None:
210
+ client = await AsyncQueueClient.from_url(
211
+ "redis://127.0.0.1:6379/0",
212
+ queue="jobs",
213
+ backend="list",
214
+ )
215
+ await client.publish({"task": "sync"})
216
+ message = await client.consume(timeout=1)
217
+ if message is not None:
218
+ await client.ack(message)
219
+ await client.close()
220
+
221
+
222
+ asyncio.run(main())
223
+ ```
224
+
225
+ 异步客户端:
226
+
227
+ ```python
228
+ import asyncio
229
+
230
+ from redqueue import AsyncQueueClient
231
+
232
+
233
+ async def main() -> None:
234
+ client = await AsyncQueueClient.from_url(
235
+ "redis://127.0.0.1:6379/0",
236
+ queue="jobs",
237
+ backend="list",
238
+ )
239
+ await client.publish({"task": "sync"})
240
+ message = await client.consume(timeout=1)
241
+ if message is not None:
242
+ await client.ack(message)
243
+ await client.close()
244
+
245
+
246
+ asyncio.run(main())
247
+ ```
248
+
249
+ Delayed task:
250
+
251
+ ```python
252
+ from redqueue import QueueClient
253
+
254
+ client = QueueClient.from_url("redis://127.0.0.1:6379/0", queue="emails")
255
+ client.delay({"to": "later@example.com"}, delay_seconds=60)
256
+ released = client.schedule_due(limit=100)
257
+ ```
258
+
259
+ 延迟任务:
260
+
261
+ ```python
262
+ from redqueue import QueueClient
263
+
264
+ client = QueueClient.from_url("redis://127.0.0.1:6379/0", queue="emails")
265
+ client.delay({"to": "later@example.com"}, delay_seconds=60)
266
+ released = client.schedule_due(limit=100)
267
+ ```
268
+
269
+ ## Documentation / 文档
270
+
271
+ - API: [docs/API.md](docs/API.md)
272
+ - Changelog: [CHANGELOG.md](CHANGELOG.md)
273
+ - Release process: [docs/RELEASE.md](docs/RELEASE.md)
274
+ - Test guide: [tests/README.md](tests/README.md)
275
+
276
+ - API 文档:[docs/API.md](docs/API.md)
277
+ - 版本变更记录:[CHANGELOG.md](CHANGELOG.md)
278
+ - 发布流程:[docs/RELEASE.md](docs/RELEASE.md)
279
+ - 测试指南:[tests/README.md](tests/README.md)
280
+
281
+ ## Testing / 测试
282
+
283
+ ```bash
284
+ PYTHONPATH=src python -m pytest
285
+ ```
286
+
287
+ Run integration tests with a local Redis server:
288
+
289
+ ```bash
290
+ REDQUEUE_REDIS_URL=redis://127.0.0.1:6379/0 PYTHONPATH=src python -m pytest -m integration
291
+ ```
292
+
293
+ 使用本地 Redis 运行集成测试:
294
+
295
+ ```bash
296
+ REDQUEUE_REDIS_URL=redis://127.0.0.1:6379/0 PYTHONPATH=src python -m pytest -m integration
297
+ ```
298
+
299
+ ## Versioning / 版本规则
300
+
301
+ Development versions and formal release versions are separate streams.
302
+ `0.10.0devN` records development milestones. The first formal release is
303
+ `0.10.0`.
304
+
305
+ 开发版本与正式版本不互通。`0.10.0devN` 用于记录开发里程碑,第一个正式版本为
306
+ `0.10.0`。
307
+
308
+ ## License / 许可证
309
+
310
+ Apache License 2.0. See [LICENSE](LICENSE).
311
+
312
+ Apache License 2.0。详见 [LICENSE](LICENSE)。