pub struct PubSub { /* private fields */ }Expand description
A connection dedicated to pubsub messages.
Implementations§
Source§impl PubSub
impl PubSub
Sourcepub async fn new<C>(
connection_info: &RedisConnectionInfo,
stream: C,
) -> RedisResult<Self>
pub async fn new<C>( connection_info: &RedisConnectionInfo, stream: C, ) -> RedisResult<Self>
Constructs a new MultiplexedConnection out of a AsyncRead + AsyncWrite object
and a ConnectionInfo
Sourcepub async fn subscribe(
&mut self,
channel_name: impl ToRedisArgs,
) -> RedisResult<()>
pub async fn subscribe( &mut self, channel_name: impl ToRedisArgs, ) -> RedisResult<()>
Subscribes to a new channel(s).
let client = redis::Client::open("redis://127.0.0.1/")?;
let mut pubsub = client.get_async_pubsub().await?;
pubsub.subscribe("channel_1").await?;
pubsub.subscribe(&["channel_2", "channel_3"]).await?;Sourcepub async fn unsubscribe(
&mut self,
channel_name: impl ToRedisArgs,
) -> RedisResult<()>
pub async fn unsubscribe( &mut self, channel_name: impl ToRedisArgs, ) -> RedisResult<()>
Unsubscribes from channel(s).
let client = redis::Client::open("redis://127.0.0.1/")?;
let mut pubsub = client.get_async_pubsub().await?;
pubsub.subscribe(&["channel_1", "channel_2"]).await?;
pubsub.unsubscribe(&["channel_1", "channel_2"]).await?;Sourcepub async fn psubscribe(
&mut self,
channel_pattern: impl ToRedisArgs,
) -> RedisResult<()>
pub async fn psubscribe( &mut self, channel_pattern: impl ToRedisArgs, ) -> RedisResult<()>
Subscribes to new channel(s) with pattern(s).
let client = redis::Client::open("redis://127.0.0.1/")?;
let mut pubsub = client.get_async_pubsub().await?;
pubsub.psubscribe("channel*_1").await?;
pubsub.psubscribe(&["channel*_2", "channel*_3"]).await?;Sourcepub async fn punsubscribe(
&mut self,
channel_pattern: impl ToRedisArgs,
) -> RedisResult<()>
pub async fn punsubscribe( &mut self, channel_pattern: impl ToRedisArgs, ) -> RedisResult<()>
Unsubscribes from channel pattern(s).
let client = redis::Client::open("redis://127.0.0.1/")?;
let mut pubsub = client.get_async_pubsub().await?;
pubsub.psubscribe(&["channel_1", "channel_2"]).await?;
pubsub.punsubscribe(&["channel_1", "channel_2"]).await?;Sourcepub async fn ping<T: FromRedisValue>(&mut self) -> RedisResult<T>
pub async fn ping<T: FromRedisValue>(&mut self) -> RedisResult<T>
Sends a ping to the server
Sourcepub async fn ping_message<T: FromRedisValue>(
&mut self,
message: impl ToRedisArgs,
) -> RedisResult<T>
pub async fn ping_message<T: FromRedisValue>( &mut self, message: impl ToRedisArgs, ) -> RedisResult<T>
Sends a ping with a message to the server
Sourcepub fn on_message(&mut self) -> impl Stream<Item = Msg> + '_
pub fn on_message(&mut self) -> impl Stream<Item = Msg> + '_
Sourcepub fn into_on_message(self) -> PubSubStream
pub fn into_on_message(self) -> PubSubStream
Sourcepub fn split(self) -> (PubSubSink, PubSubStream)
pub fn split(self) -> (PubSubSink, PubSubStream)
Splits the PubSub into separate sink and stream components, so that subscriptions could be
updated through the Sink while concurrently waiting for new messages on the Stream.
Auto Trait Implementations§
impl Freeze for PubSub
impl RefUnwindSafe for PubSub
impl Send for PubSub
impl Sync for PubSub
impl Unpin for PubSub
impl UnwindSafe for PubSub
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