You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**FastStream** supports [**Redis** pipelining](https://redis.io/docs/latest/develop/use/pipelining/){.external-link target="_blank"} to optimize performance when publishing multiple messages in a batch. This allows you to queue several **Redis** operations and execute them in one network round-trip, reducing latency significantly.
14
+
15
+
## Usage Example
16
+
17
+
```python linenums="1" hl_lines="2 11 19 22"
18
+
{! docs_src/redis/pipeline/pipeline.py !}
19
+
```
20
+
21
+
## API
22
+
23
+
You can pass the `pipeline` parameter to the `publish` method to delay the execution of **Redis** commands. The commands will only be executed after you explicitly call `#!python await pipe.execute()`.
24
+
25
+
The `pipeline` object is injected by the `Pipeline` annotation:
26
+
27
+
```python
28
+
from faststream.redis.annotations import Pipeline
29
+
```
30
+
31
+
`Pipeline` is a **Redis** pipeline object (`redis.asyncio.client.Pipeline`), which is wrapped in a FastStream dependency and will be automatically available in any subscriber.
32
+
33
+
## Batch Publishing with Pipeline
34
+
35
+
When using `#!python broker.publish_batch()` in combination with the `pipeline` parameter, all messages sent through the pipeline are queued and processed by the subscriber as a single batch after calling `#!python await pipe.execute()`. This allows the subscriber to handle all messages sent through the pipeline in a single execution, improving the efficiency of batch processing.
36
+
37
+
## Notes
38
+
39
+
- Pipelining is supported for all **Redis** queue types, including channels, lists, and streams.
40
+
- You can combine multiple queue types in a single pipeline.
41
+
42
+
## Benefits
43
+
44
+
- Reduces network traffic by batching **Redis** commands.
45
+
- Improves performance in high-volume scenarios.
46
+
- Fully integrates with **FastStream**'s dependency injection system.
47
+
- Allows for efficient batch processing when using `#!python broker.publish_batch()` and `pipeline`, as all messages are processed as a single entity by the subscriber after `#!python await pipe.execute()`.
0 commit comments