Trait PubSubCommands

Source
pub trait PubSubCommands<'a> {
    // Required methods
    async fn psubscribe<P, PP>(self, patterns: PP) -> Result<PubSubStream>
       where P: SingleArg + Send + 'a,
             PP: SingleArgCollection<P>;
    async fn ssubscribe<C, CC>(self, shardchannels: CC) -> Result<PubSubStream>
       where C: SingleArg + Send + 'a,
             CC: SingleArgCollection<C>;
    async fn subscribe<C, CC>(self, channels: CC) -> Result<PubSubStream>
       where C: SingleArg + Send + 'a,
             CC: SingleArgCollection<C>;

    // Provided methods
    fn publish<C, M>(
        self,
        channel: C,
        message: M,
    ) -> PreparedCommand<'a, Self, usize>
       where Self: Sized,
             C: SingleArg,
             M: SingleArg { ... }
    fn pub_sub_channels<C, CC>(
        self,
        options: PubSubChannelsOptions,
    ) -> PreparedCommand<'a, Self, CC>
       where Self: Sized,
             C: PrimitiveResponse + DeserializeOwned,
             CC: CollectionResponse<C> { ... }
    fn pub_sub_numpat(self) -> PreparedCommand<'a, Self, usize>
       where Self: Sized { ... }
    fn pub_sub_numsub<C, CC, R, RR>(
        self,
        channels: CC,
    ) -> PreparedCommand<'a, Self, RR>
       where Self: Sized,
             C: SingleArg,
             CC: SingleArgCollection<C>,
             R: PrimitiveResponse,
             RR: KeyValueCollectionResponse<R, usize> { ... }
    fn pub_sub_shardchannels<C, CC>(
        self,
        options: PubSubChannelsOptions,
    ) -> PreparedCommand<'a, Self, CC>
       where Self: Sized,
             C: PrimitiveResponse + DeserializeOwned,
             CC: CollectionResponse<C> { ... }
    fn pub_sub_shardnumsub<C, CC, R, RR>(
        self,
        channels: CC,
    ) -> PreparedCommand<'a, Self, RR>
       where Self: Sized,
             C: SingleArg,
             CC: SingleArgCollection<C>,
             R: PrimitiveResponse,
             RR: KeyValueCollectionResponse<R, usize> { ... }
    fn spublish<C, M>(
        self,
        shardchannel: C,
        message: M,
    ) -> PreparedCommand<'a, Self, usize>
       where Self: Sized,
             C: SingleArg,
             M: SingleArg { ... }
}
Expand description

A group of Redis commands related to Pub/Sub

§See Also

Redis Pub/Sub Commands

Required Methods§

Source

async fn psubscribe<P, PP>(self, patterns: PP) -> Result<PubSubStream>
where P: SingleArg + Send + 'a, PP: SingleArgCollection<P>,

Subscribes the client to the given patterns.

§Example
use rustis::{
    client::{Client, ClientPreparedCommand},
    commands::{FlushingMode, PubSubCommands, ServerCommands},
    resp::cmd,
    Result,
};
use futures_util::StreamExt;

#[cfg_attr(feature = "tokio-runtime", tokio::main)]
#[cfg_attr(feature = "async-std-runtime", async_std::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 message = pub_sub_stream.next().await.unwrap()?;
    assert_eq!(b"mychannel*".to_vec(), message.pattern);
    assert_eq!(b"mychannel1".to_vec(), message.channel);
    assert_eq!(b"mymessage".to_vec(), message.payload);

    pub_sub_stream.close().await?;

    Ok(())
}
§See Also

https://redis.io/commands/psubscribe/

Source

async fn ssubscribe<C, CC>(self, shardchannels: CC) -> Result<PubSubStream>
where C: SingleArg + Send + 'a, CC: SingleArgCollection<C>,

Subscribes the client to the specified channels.

§See Also

https://redis.io/commands/subscribe/

Source

async fn subscribe<C, CC>(self, channels: CC) -> Result<PubSubStream>
where C: SingleArg + Send + 'a, CC: SingleArgCollection<C>,

Subscribes the client to the specified channels.

§Example
use rustis::{
    client::{Client, ClientPreparedCommand},
    commands::{FlushingMode, PubSubCommands, ServerCommands},
    resp::cmd,
    Result,
};
use futures_util::StreamExt;

#[cfg_attr(feature = "tokio-runtime", tokio::main)]
#[cfg_attr(feature = "async-std-runtime", async_std::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 message = pub_sub_stream.next().await.unwrap()?;
    assert_eq!(b"mychannel".to_vec(), message.channel);
    assert_eq!(b"mymessage".to_vec(), message.payload);

    pub_sub_stream.close().await?;

    Ok(())
}
§See Also

https://redis.io/commands/subscribe/

Provided Methods§

Source

fn publish<C, M>( self, channel: C, message: M, ) -> PreparedCommand<'a, Self, usize>
where Self: Sized, C: SingleArg, M: SingleArg,

Posts a message to the given channel.

§Return

The number of clients that received the message.

Note that in a Redis Cluster, only clients that are connected to the same node as the publishing client are included in the count.

§See Also

https://redis.io/commands/publish/

Source

fn pub_sub_channels<C, CC>( self, options: PubSubChannelsOptions, ) -> PreparedCommand<'a, Self, CC>

Lists the currently active channels.

§Return

A collection of active channels, optionally matching the specified pattern.

§See Also

https://redis.io/commands/pubsub-channels/

Source

fn pub_sub_numpat(self) -> PreparedCommand<'a, Self, usize>
where Self: Sized,

Returns the number of unique patterns that are subscribed to by clients (that are performed using the PSUBSCRIBE command).

§Return

The number of patterns all the clients are subscribed to.

§See Also

https://redis.io/commands/pubsub-numpat/

Source

fn pub_sub_numsub<C, CC, R, RR>( self, channels: CC, ) -> PreparedCommand<'a, Self, RR>

Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified channels.

§Return

A collection of channels and number of subscribers for every channel.

§See Also

https://redis.io/commands/pubsub-numsub/

Source

fn pub_sub_shardchannels<C, CC>( self, options: PubSubChannelsOptions, ) -> PreparedCommand<'a, Self, CC>

Lists the currently active shard channels.

§Return

A collection of active channels, optionally matching the specified pattern.

§See Also

https://redis.io/commands/pubsub-shardchannels/

Source

fn pub_sub_shardnumsub<C, CC, R, RR>( self, channels: CC, ) -> PreparedCommand<'a, Self, RR>

Returns the number of subscribers for the specified shard channels.

§Return

A collection of channels and number of subscribers for every channel.

§See Also

https://redis.io/commands/pubsub-shardnumsub/

Source

fn spublish<C, M>( self, shardchannel: C, message: M, ) -> PreparedCommand<'a, Self, usize>
where Self: Sized, C: SingleArg, M: SingleArg,

Posts a message to the given shard channel.

§Return

The number of clients that received the message.

§See Also

https://redis.io/commands/spublish/

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.

Implementors§

Source§

impl<'a> PubSubCommands<'a> for &'a Client