pub struct PubSub<'a> { /* private fields */ }
Expand description
Represents a pubsub connection.
Implementations
sourceimpl<'a> PubSub<'a>
impl<'a> PubSub<'a>
The pubsub object provides convenient access to the redis pubsub system. Once created you can subscribe and unsubscribe from channels and listen in on messages.
Example:
let client = redis::Client::open("redis://127.0.0.1/")?;
let mut con = client.get_connection()?;
let mut pubsub = con.as_pubsub();
pubsub.subscribe("channel_1")?;
pubsub.subscribe("channel_2")?;
loop {
let msg = pubsub.get_message()?;
let payload : String = msg.get_payload()?;
println!("channel '{}': {}", msg.get_channel_name(), payload);
}
sourcepub fn subscribe<T: ToRedisArgs>(&mut self, channel: T) -> RedisResult<()>
pub fn subscribe<T: ToRedisArgs>(&mut self, channel: T) -> RedisResult<()>
Subscribes to a new channel.
sourcepub fn psubscribe<T: ToRedisArgs>(&mut self, pchannel: T) -> RedisResult<()>
pub fn psubscribe<T: ToRedisArgs>(&mut self, pchannel: T) -> RedisResult<()>
Subscribes to a new channel with a pattern.
sourcepub fn unsubscribe<T: ToRedisArgs>(&mut self, channel: T) -> RedisResult<()>
pub fn unsubscribe<T: ToRedisArgs>(&mut self, channel: T) -> RedisResult<()>
Unsubscribes from a channel.
sourcepub fn punsubscribe<T: ToRedisArgs>(&mut self, pchannel: T) -> RedisResult<()>
pub fn punsubscribe<T: ToRedisArgs>(&mut self, pchannel: T) -> RedisResult<()>
Unsubscribes from a channel with a pattern.
sourcepub fn get_message(&mut self) -> RedisResult<Msg>
pub fn get_message(&mut self) -> RedisResult<Msg>
Fetches the next message from the pubsub connection. Blocks until a message becomes available. This currently does not provide a wait not to block :(
The message itself is still generic and can be converted into an appropriate type through the helper methods on it.
sourcepub fn set_read_timeout(&self, dur: Option<Duration>) -> RedisResult<()>
pub fn set_read_timeout(&self, dur: Option<Duration>) -> RedisResult<()>
Sets the read timeout for the connection.
If the provided value is None
, then get_message
call will
block indefinitely. It is an error to pass the zero Duration
to this
method.
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for PubSub<'a>
impl<'a> Send for PubSub<'a>
impl<'a> Sync for PubSub<'a>
impl<'a> Unpin for PubSub<'a>
impl<'a> !UnwindSafe for PubSub<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more