Skip to content

Commit 4193dfc

Browse files
authored
feat: Add Redis queue support for S3 event notifications (#1189)
* feat: Add Redis queue support for S3 event notifications - Add Redis client dependency to Cargo.toml - Extend Amazon S3 source to support Redis pub/sub for event notifications - Add redis_url and redis_channel configuration options - Implement RedisContext with async pub/sub support - Update change_stream to prefer Redis over SQS when both are configured - Add comprehensive documentation for MinIO Redis setup - Update Python spec to include Redis configuration fields This enables MinIO users to receive S3-compatible event notifications without requiring AWS SQS, addressing issue #599. * refactor: address maintainer feedback for Redis configuration - Remove timeout logic in Redis polling to prevent error masking - Wrap Redis URL and channel in dedicated RedisConfig/RedisNotification structs - Improve code organization and follow project patterns
1 parent 47154bd commit 4193dfc

File tree

5 files changed

+255
-19
lines changed

5 files changed

+255
-19
lines changed

Cargo.lock

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,6 @@ azure_storage_blobs = { version = "0.21.0", default-features = false, features =
152152
"hmac_rust",
153153
] }
154154
serde_path_to_error = "0.1.17"
155+
redis = { version = "0.31.0", features = ["tokio-comp", "connection-manager"] }
155156
expect-test = "1.5.0"
156157
encoding_rs = "0.8.35"

docs/docs/sources/amazons3.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,33 @@ This is how to setup:
8686

8787
AWS's [Guide of Configuring a Bucket for Notifications](https://docs.aws.amazon.com/AmazonS3/latest/userguide/ways-to-add-notification-config-to-bucket.html#step1-create-sqs-queue-for-notification) provides more details.
8888

89+
#### (Alternative) Setup Redis for event notifications (MinIO)
90+
91+
For MinIO setups that don't use AWS SQS, you can configure MinIO to publish event notifications to Redis:
92+
93+
* Configure MinIO to publish events to Redis by setting environment variables:
94+
```bash
95+
export MINIO_NOTIFY_REDIS_ENABLE="on"
96+
export MINIO_NOTIFY_REDIS_ADDRESS="redis-endpoint.example.net:6379"
97+
export MINIO_NOTIFY_REDIS_KEY="bucketevents"
98+
export MINIO_NOTIFY_REDIS_FORMAT="namespace"
99+
```
100+
Replace the values with your Redis server details.
101+
102+
* Alternatively, use the `mc` command-line tool:
103+
```bash
104+
mc alias set myminio http://minio.example.com:9000 ACCESSKEY SECRETKEY
105+
mc admin config set myminio/ notify_redis \
106+
address="redis-endpoint.example.net:6379" \
107+
key="bucketevents" \
108+
format="namespace"
109+
mc admin service restart myminio
110+
```
111+
112+
* Ensure your Redis server is accessible and configured to accept connections from MinIO.
113+
114+
MinIO's [Redis Notification Settings](https://min.io/docs/minio/linux/reference/minio-server/settings/notifications/redis.html) documentation provides more details on configuration options.
115+
89116
### Spec
90117

91118
The spec takes the following fields:
@@ -113,6 +140,17 @@ The spec takes the following fields:
113140

114141
:::
115142

143+
* `redis_url` (`str`, optional): if provided, the source will receive change event notifications via Redis pub/sub. This is particularly useful for MinIO setups that publish events to Redis instead of SQS.
144+
145+
* `redis_channel` (`str`, optional): the Redis channel to subscribe to for event notifications. Required when `redis_url` is provided.
146+
147+
:::info
148+
149+
Redis pub/sub is preferred over SQS when both are configured. This allows MinIO users to receive S3-compatible event notifications without requiring AWS SQS.
150+
The Redis implementation expects S3 event notifications in the same JSON format as SQS messages.
151+
152+
:::
153+
116154
### Schema
117155

118156
The output is a [*KTable*](/docs/core/data_types#ktable) with the following sub fields:

python/cocoindex/sources/_engine_builtin_specs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ class GoogleDrive(op.SourceSpec):
3535
recent_changes_poll_interval: datetime.timedelta | None = None
3636

3737

38+
@dataclass
39+
class RedisNotification:
40+
"""Redis pub/sub configuration for event notifications."""
41+
42+
# Redis server URL (e.g., "redis://localhost:6379")
43+
redis_url: str
44+
# Redis channel name for pub/sub notifications
45+
redis_channel: str
46+
47+
3848
class AmazonS3(op.SourceSpec):
3949
"""Import data from an Amazon S3 bucket. Supports optional prefix and file filtering by glob patterns."""
4050

@@ -46,6 +56,7 @@ class AmazonS3(op.SourceSpec):
4656
included_patterns: list[str] | None = None
4757
excluded_patterns: list[str] | None = None
4858
sqs_queue_url: str | None = None
59+
redis: RedisNotification | None = None
4960

5061

5162
class AzureBlob(op.SourceSpec):

0 commit comments

Comments
 (0)