pub struct Subscriber { /* private fields */ }Expand description
One subscribed TCP connection. Owns the socket; not Sync.
Implementations§
Source§impl Subscriber
impl Subscriber
Sourcepub fn connect(url: &str) -> Result<Self>
pub fn connect(url: &str) -> Result<Self>
Open a fresh TCP connection without subscribing to anything.
Use Self::subscribe / Self::psubscribe next.
Accepted URL schemes: kevy://, redis://, tcp:// (all wire-identical).
mem:// / file:// return ErrorKind::Unsupported — there is no
other process to receive messages from inside an embedded store.
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. After the
call returns, the server has the SUBSCRIBE command queued — drain
the per-channel ack frames with Self::recv before
you act on Message events.
Returns ErrorKind::InvalidInput if channels is empty (use
Self::connect + Self::psubscribe for a pattern-only start).
Sourcepub fn subscribe(&mut self, channels: &[&[u8]]) -> Result<()>
pub fn subscribe(&mut self, channels: &[&[u8]]) -> Result<()>
SUBSCRIBE channel [channel ...]. Returns once the bytes are written;
the server sends one Subscribe ack per channel — drain with
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
(*, ?, […]). Same ack-draining note as Self::subscribe.
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, parse it, classify it.
recv itself never times out — apply a read timeout via
Self::set_read_timeout if you need bounded blocking.
Server close yields ErrorKind::UnexpectedEof; a malformed RESP
frame yields ErrorKind::InvalidData.
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 on the underlying socket.
After setting Some(dur), Self::recv will return an io::Error
of kind WouldBlock / TimedOut if no data arrives within dur.