pub struct Subscriber { /* private fields */ }Expand description
A connection locked into pub/sub mode.
Obtained by calling Client::subscribe or Client::psubscribe.
The underlying transport is consumed — create a separate Client
for regular commands while this subscriber is active.
§Example
use ember_client::Client;
#[tokio::main]
async fn main() -> Result<(), ember_client::ClientError> {
let mut publisher = Client::connect("127.0.0.1", 6379).await?;
let subscriber_conn = Client::connect("127.0.0.1", 6379).await?;
let mut sub = subscriber_conn.subscribe(&["news"]).await?;
publisher.publish("news", "breaking: hello world").await?;
let msg = sub.recv().await?;
println!("got: {:?}", msg.data);
Ok(())
}Implementations§
Source§impl Subscriber
impl Subscriber
Sourcepub async fn recv(&mut self) -> Result<Message, ClientError>
pub async fn recv(&mut self) -> Result<Message, ClientError>
Blocks until the next message arrives on any subscribed channel.
Subscription confirmation frames (subscribe/psubscribe) are
skipped silently — only actual message frames are returned.
Sourcepub async fn subscribe(&mut self, channels: &[&str]) -> Result<(), ClientError>
pub async fn subscribe(&mut self, channels: &[&str]) -> Result<(), ClientError>
Subscribes to additional channels without leaving sub mode.
Sourcepub async fn unsubscribe(self, channels: &[&str]) -> Result<Client, ClientError>
pub async fn unsubscribe(self, channels: &[&str]) -> Result<Client, ClientError>
Unsubscribes from the given channels.
When all subscriptions have been removed the inner Client is
returned so the connection can be reused for regular commands.
Auto Trait Implementations§
impl !Freeze for Subscriber
impl !RefUnwindSafe for Subscriber
impl Send for Subscriber
impl Sync for Subscriber
impl Unpin for Subscriber
impl UnsafeUnpin for Subscriber
impl !UnwindSafe for Subscriber
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more