pub struct PubSub<'a> { /* private fields */ }Expand description
Represents a pubsub connection.
Implementations§
Source§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.
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>(&mut self, channel: T) -> Result<(), RedisError>where
T: ToRedisArgs,
pub fn subscribe<T>(&mut self, channel: T) -> Result<(), RedisError>where
T: ToRedisArgs,
Subscribes to a new channel(s).
Sourcepub fn psubscribe<T>(&mut self, pchannel: T) -> Result<(), RedisError>where
T: ToRedisArgs,
pub fn psubscribe<T>(&mut self, pchannel: T) -> Result<(), RedisError>where
T: ToRedisArgs,
Subscribes to new channel(s) with pattern(s).
Sourcepub fn unsubscribe<T>(&mut self, channel: T) -> Result<(), RedisError>where
T: ToRedisArgs,
pub fn unsubscribe<T>(&mut self, channel: T) -> Result<(), RedisError>where
T: ToRedisArgs,
Unsubscribes from a channel(s).
Sourcepub fn punsubscribe<T>(&mut self, pchannel: T) -> Result<(), RedisError>where
T: ToRedisArgs,
pub fn punsubscribe<T>(&mut self, pchannel: T) -> Result<(), RedisError>where
T: ToRedisArgs,
Unsubscribes from channel pattern(s).
Sourcepub fn ping_message<T>(
&mut self,
message: impl ToRedisArgs,
) -> Result<T, RedisError>where
T: FromRedisValue,
pub fn ping_message<T>(
&mut self,
message: impl ToRedisArgs,
) -> Result<T, RedisError>where
T: FromRedisValue,
Sends a ping with a message to the server
Sourcepub fn ping<T>(&mut self) -> Result<T, RedisError>where
T: FromRedisValue,
pub fn ping<T>(&mut self) -> Result<T, RedisError>where
T: FromRedisValue,
Sends a ping to the server
Sourcepub fn get_message(&mut self) -> Result<Msg, RedisError>
pub fn get_message(&mut self) -> Result<Msg, RedisError>
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>) -> Result<(), RedisError>
pub fn set_read_timeout(&self, dur: Option<Duration>) -> Result<(), RedisError>
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> !UnwindSafe for PubSub<'a>
impl<'a> Freeze for PubSub<'a>
impl<'a> Send for PubSub<'a>
impl<'a> Sync for PubSub<'a>
impl<'a> Unpin for PubSub<'a>
impl<'a> UnsafeUnpin for PubSub<'a>
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
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more