Trait redis_driver::PubSubCommands
source · [−]pub trait PubSubCommands<T>: PrepareCommand<T> {
fn psubscribe<'a, P, PP>(&'a self, patterns: PP) -> Future<'a, PubSubStream>
where
P: Into<BulkString> + Send + 'a,
PP: SingleArgOrCollection<P>;
fn subscribe<'a, C, CC>(&'a self, channels: CC) -> Future<'a, PubSubStream>
where
C: Into<BulkString> + Send + 'a,
CC: SingleArgOrCollection<C>;
fn publish<C, M>(&self, channel: C, message: M) -> CommandResult<'_, T, usize>
where
C: Into<BulkString>,
M: Into<BulkString>,
{ ... }
fn pub_sub_channels<C, CC>(
&self,
options: PubSubChannelsOptions
) -> CommandResult<'_, T, CC>
where
C: FromValue,
CC: FromSingleValueArray<C>,
{ ... }
fn pub_sub_numpat(&self) -> CommandResult<'_, T, usize> { ... }
fn pub_sub_numsub<C, CC, R, RR>(
&self,
channels: CC
) -> CommandResult<'_, T, RR>
where
C: Into<BulkString>,
CC: SingleArgOrCollection<C>,
R: FromValue,
RR: FromKeyValueValueArray<R, usize>,
{ ... }
}
Expand description
Required Methods
sourcefn psubscribe<'a, P, PP>(&'a self, patterns: PP) -> Future<'a, PubSubStream>where
P: Into<BulkString> + Send + 'a,
PP: SingleArgOrCollection<P>,
fn psubscribe<'a, P, PP>(&'a self, patterns: PP) -> Future<'a, PubSubStream>where
P: Into<BulkString> + Send + 'a,
PP: SingleArgOrCollection<P>,
Subscribes the client to the given patterns.
Example
use redis_driver::{
resp::cmd, Client, ClientCommandResult, FlushingMode,
PubSubCommands, ServerCommands, Result
};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<()> {
let pub_sub_client = Client::connect("127.0.0.1:6379").await?;
let 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 subscribe<'a, C, CC>(&'a self, channels: CC) -> Future<'a, PubSubStream>where
C: Into<BulkString> + Send + 'a,
CC: SingleArgOrCollection<C>,
fn subscribe<'a, C, CC>(&'a self, channels: CC) -> Future<'a, PubSubStream>where
C: Into<BulkString> + Send + 'a,
CC: SingleArgOrCollection<C>,
Subscribes the client to the specified channels.
Example
use redis_driver::{
resp::cmd, Client, ClientCommandResult, FlushingMode,
PubSubCommands, ServerCommands, Result
};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<()> {
let pub_sub_client = Client::connect("127.0.0.1:6379").await?;
let 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(())
}