Redis publisher
Redis publisher implementation (optional dependency).
This publisher uses the redis-py asyncio client to publish events via: - Pub/Sub channels (default), or - Redis Streams (XADD) when configured with mode="stream".
Dependency: redis>=4.2 (provides redis.asyncio).
Not installed by default; install extra: pip install pyagenity[redis]
.
Classes:
Name | Description |
---|---|
RedisPublisher |
Publish events to Redis via Pub/Sub channel or Stream. |
Attributes:
Name | Type | Description |
---|---|---|
logger |
|
Attributes¶
Classes¶
RedisPublisher
¶
Bases: BasePublisher
Publish events to Redis via Pub/Sub channel or Stream.
Attributes:
Name | Type | Description |
---|---|---|
url |
str
|
Redis URL. |
mode |
str
|
Publishing mode ('pubsub' or 'stream'). |
channel |
str
|
Pub/Sub channel name. |
stream |
str
|
Stream name. |
maxlen |
int | None
|
Max length for streams. |
encoding |
str
|
Encoding for messages. |
_redis |
Redis client instance. |
Methods:
Name | Description |
---|---|
__init__ |
Initialize the RedisPublisher. |
close |
Close the Redis client. |
publish |
Publish an event to Redis. |
sync_close |
Synchronously close the Redis client. |
Source code in pyagenity/publisher/redis_publisher.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
Attributes¶
Functions¶
__init__
¶
__init__(config=None)
Initialize the RedisPublisher.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
dict[str, Any] | None
|
Configuration dictionary. Supported keys: - url: Redis URL (default: "redis://localhost:6379/0"). - mode: Publishing mode ('pubsub' or 'stream', default: 'pubsub'). - channel: Pub/Sub channel name (default: "pyagenity.events"). - stream: Stream name (default: "pyagenity.events"). - maxlen: Max length for streams. - encoding: Encoding (default: "utf-8"). |
None
|
Source code in pyagenity/publisher/redis_publisher.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
close
async
¶
close()
Close the Redis client.
Source code in pyagenity/publisher/redis_publisher.py
114 115 116 117 118 119 120 121 122 123 |
|
publish
async
¶
publish(event)
Publish an event to Redis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
EventModel
|
The event to publish. |
required |
Returns:
Type | Description |
---|---|
Any
|
The result of the publish operation. |
Source code in pyagenity/publisher/redis_publisher.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
sync_close
¶
sync_close()
Synchronously close the Redis client.
Source code in pyagenity/publisher/redis_publisher.py
125 126 127 128 129 130 131 |
|