pub trait PubSubCommands {
// Required methods
fn psubscribe<'a, P, PP>(
&'a mut self,
patterns: PP,
) -> Future<'a, PubSubStream>
where P: Into<CommandArg> + Send + 'a,
PP: SingleArgOrCollection<P>;
fn ssubscribe<'a, C, CC>(
&'a mut self,
shardchannels: CC,
) -> Future<'a, PubSubStream>
where C: Into<CommandArg> + Send + 'a,
CC: SingleArgOrCollection<C>;
fn subscribe<'a, C, CC>(
&'a mut self,
channels: CC,
) -> Future<'a, PubSubStream>
where C: Into<CommandArg> + Send + 'a,
CC: SingleArgOrCollection<C>;
// Provided methods
fn publish<C, M>(
&mut self,
channel: C,
message: M,
) -> PreparedCommand<'_, Self, usize>
where Self: Sized,
C: Into<CommandArg>,
M: Into<CommandArg> { ... }
fn pub_sub_channels<C, CC>(
&mut self,
options: PubSubChannelsOptions,
) -> PreparedCommand<'_, Self, CC>
where Self: Sized,
C: FromValue,
CC: FromSingleValueArray<C> { ... }
fn pub_sub_numpat(&mut self) -> PreparedCommand<'_, Self, usize>
where Self: Sized { ... }
fn pub_sub_numsub<C, CC, R, RR>(
&mut self,
channels: CC,
) -> PreparedCommand<'_, Self, RR>
where Self: Sized,
C: Into<CommandArg>,
CC: SingleArgOrCollection<C>,
R: FromValue,
RR: FromKeyValueValueArray<R, usize> { ... }
fn pub_sub_shardchannels<C, CC>(
&mut self,
options: PubSubChannelsOptions,
) -> PreparedCommand<'_, Self, CC>
where Self: Sized,
C: FromValue,
CC: FromSingleValueArray<C> { ... }
fn pub_sub_shardnumsub<C, CC, R, RR>(
&mut self,
channels: CC,
) -> PreparedCommand<'_, Self, RR>
where Self: Sized,
C: Into<CommandArg>,
CC: SingleArgOrCollection<C>,
R: FromValue,
RR: FromKeyValueValueArray<R, usize> { ... }
fn spublish<C, M>(
&mut self,
shardchannel: C,
message: M,
) -> PreparedCommand<'_, Self, usize>
where Self: Sized,
C: Into<CommandArg>,
M: Into<CommandArg> { ... }
}
Expand description
Required Methods§
Sourcefn psubscribe<'a, P, PP>(&'a mut self, patterns: PP) -> Future<'a, PubSubStream>
fn psubscribe<'a, P, PP>(&'a mut self, patterns: PP) -> Future<'a, PubSubStream>
Subscribes the client to the given patterns.
§Example
use redis_driver::{
resp::cmd, Client, ClientPreparedCommand, FlushingMode,
PubSubCommands, ServerCommands, Result
};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<()> {
let mut pub_sub_client = Client::connect("127.0.0.1:6379").await?;
let mut regular_client = Client::connect("127.0.0.1:6379").await?;
regular_client.flushdb(FlushingMode::Sync).await?;
let mut pub_sub_stream = pub_sub_client.psubscribe("mychannel*").await?;
regular_client.publish("mychannel1", "mymessage").await?;
let (pattern, channel, message): (String, String, String) = pub_sub_stream
.next()
.await
.unwrap()?
.into()?;
assert_eq!("mychannel*", pattern);
assert_eq!("mychannel1", channel);
assert_eq!("mymessage", message);
pub_sub_stream.close().await?;
Ok(())
}
§See Also
Sourcefn ssubscribe<'a, C, CC>(
&'a mut self,
shardchannels: CC,
) -> Future<'a, PubSubStream>
fn ssubscribe<'a, C, CC>( &'a mut self, shardchannels: CC, ) -> Future<'a, PubSubStream>
Sourcefn subscribe<'a, C, CC>(&'a mut self, channels: CC) -> Future<'a, PubSubStream>
fn subscribe<'a, C, CC>(&'a mut self, channels: CC) -> Future<'a, PubSubStream>
Subscribes the client to the specified channels.
§Example
use redis_driver::{
resp::cmd, Client, ClientPreparedCommand, FlushingMode,
PubSubCommands, ServerCommands, Result
};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<()> {
let mut pub_sub_client = Client::connect("127.0.0.1:6379").await?;
let mut regular_client = Client::connect("127.0.0.1:6379").await?;
regular_client.flushdb(FlushingMode::Sync).await?;
let mut pub_sub_stream = pub_sub_client.subscribe("mychannel").await?;
regular_client.publish("mychannel", "mymessage").await?;
let (channel, message): (String, String) = pub_sub_stream
.next()
.await
.unwrap()?
.into()?;
assert_eq!("mychannel", channel);
assert_eq!("mymessage", message);
pub_sub_stream.close().await?;
Ok(())
}
§See Also
Provided Methods§
Sourcefn publish<C, M>(
&mut self,
channel: C,
message: M,
) -> PreparedCommand<'_, Self, usize>
fn publish<C, M>( &mut self, channel: C, message: M, ) -> PreparedCommand<'_, Self, usize>
Sourcefn pub_sub_channels<C, CC>(
&mut self,
options: PubSubChannelsOptions,
) -> PreparedCommand<'_, Self, CC>
fn pub_sub_channels<C, CC>( &mut self, options: PubSubChannelsOptions, ) -> PreparedCommand<'_, Self, CC>
Sourcefn pub_sub_numpat(&mut self) -> PreparedCommand<'_, Self, usize>where
Self: Sized,
fn pub_sub_numpat(&mut self) -> PreparedCommand<'_, Self, usize>where
Self: Sized,
Sourcefn pub_sub_numsub<C, CC, R, RR>(
&mut self,
channels: CC,
) -> PreparedCommand<'_, Self, RR>where
Self: Sized,
C: Into<CommandArg>,
CC: SingleArgOrCollection<C>,
R: FromValue,
RR: FromKeyValueValueArray<R, usize>,
fn pub_sub_numsub<C, CC, R, RR>(
&mut self,
channels: CC,
) -> PreparedCommand<'_, Self, RR>where
Self: Sized,
C: Into<CommandArg>,
CC: SingleArgOrCollection<C>,
R: FromValue,
RR: FromKeyValueValueArray<R, usize>,
Sourcefn pub_sub_shardchannels<C, CC>(
&mut self,
options: PubSubChannelsOptions,
) -> PreparedCommand<'_, Self, CC>
fn pub_sub_shardchannels<C, CC>( &mut self, options: PubSubChannelsOptions, ) -> PreparedCommand<'_, Self, CC>
Sourcefn pub_sub_shardnumsub<C, CC, R, RR>(
&mut self,
channels: CC,
) -> PreparedCommand<'_, Self, RR>where
Self: Sized,
C: Into<CommandArg>,
CC: SingleArgOrCollection<C>,
R: FromValue,
RR: FromKeyValueValueArray<R, usize>,
fn pub_sub_shardnumsub<C, CC, R, RR>(
&mut self,
channels: CC,
) -> PreparedCommand<'_, Self, RR>where
Self: Sized,
C: Into<CommandArg>,
CC: SingleArgOrCollection<C>,
R: FromValue,
RR: FromKeyValueValueArray<R, usize>,
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.