Skip to main content

anycms_event_redis/
lib.rs

1//! Redis transport for the anycms-event distributed event bus.
2//!
3//! This crate provides [`RedisTransport`] for bridging local [`EventBus`](anycms_event::EventBus)
4//! instances across multiple processes using Redis Pub/Sub as the transport layer.
5//!
6//! # Quick Start
7//!
8//! ```ignore
9//! use anycms_event::EventBus;
10//! use anycms_event_redis::RedisTransport;
11//!
12//! #[tokio::main]
13//! async fn main() {
14//!     let transport = RedisTransport::new("redis://127.0.0.1:6379")
15//!         .await
16//!         .expect("Failed to connect to Redis");
17//!
18//!     let bus = EventBus::new();
19//!     let bridged = transport.bridge(bus).await.unwrap();
20//!
21//!     // Forward remote events of a specific type to the local bus
22//!     bridged.forward_from_redis::<MyEvent>().await.unwrap();
23//!
24//!     // Subscribe locally (receives both local and remote events)
25//!     bridged.subscribe(|event: MyEvent| async move {
26//!         println!("Received: {:?}", event);
27//!         Ok(())
28//!     }).await.unwrap();
29//!
30//!     // Publish to local subscribers AND Redis
31//!     bridged.publish(MyEvent { /* ... */ }).await.unwrap();
32//! }
33//! ```
34
35pub mod error;
36pub mod transport;
37
38pub use error::{RedisTransportError, Result};
39pub use transport::{BridgedEventBus, ForwarderHandle, RedisTransport, RedisTransportSubscription};