pub struct Subscriber { /* private fields */ }Expand description
One subscribed connection. Owns either a TCP socket or an in-process
Subscription; the variant is chosen by the URL scheme in
Subscriber::open / Subscriber::connect.
Implementations§
Source§impl Subscriber
impl Subscriber
Sourcepub fn connect(url: &str) -> Result<Self>
pub fn connect(url: &str) -> Result<Self>
Open a fresh connection without subscribing to anything yet. Call
Self::subscribe / Self::psubscribe next.
Accepted URLs:
kevy://,redis://,tcp://— TCP RESP servermem://<name>,file:///path— in-process shared busmem://(anonymous),rediss://,kevys://,redis://user:pass@…are rejected withio::ErrorKind::Unsupported
Sourcepub fn open(url: &str, channels: &[&[u8]]) -> Result<Self>
pub fn open(url: &str, channels: &[&[u8]]) -> Result<Self>
Open and subscribe to one or more channels in one step. Returns
ErrorKind::InvalidInput if channels is empty (use
Self::connect for an empty start).
Sourcepub fn subscribe(&mut self, channels: &[&[u8]]) -> Result<()>
pub fn subscribe(&mut self, channels: &[&[u8]]) -> Result<()>
SUBSCRIBE channel [channel ...]. Per-channel Subscribe acks
are delivered via Self::recv.
Sourcepub fn psubscribe(&mut self, patterns: &[&[u8]]) -> Result<()>
pub fn psubscribe(&mut self, patterns: &[&[u8]]) -> Result<()>
PSUBSCRIBE pattern [pattern ...]. Patterns use Redis glob syntax
(*, ?, […]).
Sourcepub fn unsubscribe(&mut self, channels: &[&[u8]]) -> Result<()>
pub fn unsubscribe(&mut self, channels: &[&[u8]]) -> Result<()>
UNSUBSCRIBE [channel ...]. Empty channels unsubscribes from
every channel (Redis wire semantics).
Sourcepub fn punsubscribe(&mut self, patterns: &[&[u8]]) -> Result<()>
pub fn punsubscribe(&mut self, patterns: &[&[u8]]) -> Result<()>
PUNSUBSCRIBE [pattern ...]. Empty patterns unsubscribes from
every pattern.
Sourcepub fn recv(&mut self) -> Result<PubsubEvent>
pub fn recv(&mut self) -> Result<PubsubEvent>
Block until the next pubsub frame arrives. Apply
Self::set_read_timeout for bounded blocking.
Connection close / bus tear-down yields ErrorKind::UnexpectedEof.
Sourcepub fn set_read_timeout(&mut self, dur: Option<Duration>) -> Result<()>
pub fn set_read_timeout(&mut self, dur: Option<Duration>) -> Result<()>
Apply (or clear) a read timeout. After setting Some(dur),
Self::recv returns an io::Error of kind WouldBlock /
TimedOut when no frame arrives within dur.