1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::{
    client::{prepare_command, PreparedCommand},
    resp::{cmd, SingleArg, SingleArgCollection, Value},
};

/// A group of Redis commands related to [`Pub/Sub`](https://redis.io/docs/manual/pubsub/)
/// # See Also
/// [Redis Pub/Sub Commands](https://redis.io/commands/?group=pubsub)
pub(crate) trait InternalPubSubCommands {
    fn psubscribe<P, PP>(&mut self, patterns: PP) -> PreparedCommand<Self, Value>
    where
        Self: Sized,
        P: SingleArg,
        PP: SingleArgCollection<P>
    {
        prepare_command(self, cmd("PSUBSCRIBE").arg(patterns))
    }

    /// Unsubscribes the client from the given patterns, or from all of them if none is given.
    ///
    /// # See Also
    /// [<https://redis.io/commands/punsubscribe/>](https://redis.io/commands/punsubscribe/)            
    fn punsubscribe<P, PP>(&mut self, patterns: PP) -> PreparedCommand<Self, ()>
    where
        Self: Sized,
        P: SingleArg + Send,
        PP: SingleArgCollection<P>,
    {
        prepare_command(self, cmd("PUNSUBSCRIBE").arg(patterns))
    }

    fn ssubscribe<C, CC>(&mut self, shardchannels: CC) -> PreparedCommand<Self, Value>
    where
        Self: Sized,
        C: SingleArg,
        CC: SingleArgCollection<C>
    {
        prepare_command(self, cmd("SSUBSCRIBE").arg(shardchannels))
    }

    fn subscribe<C, CC>(&mut self, channels: CC) -> PreparedCommand<Self, Value>
    where
        Self: Sized,
        C: SingleArg,
        CC: SingleArgCollection<C>
    {
        prepare_command(self, cmd("SUBSCRIBE").arg(channels))
    }

    /// Unsubscribes the client from the given shard channels, or from all of them if none is given.
    ///
    /// # See Also
    /// [<https://redis.io/commands/sunsubscribe//>](https://redis.io/commands/sunsubscribe//)            
    fn sunsubscribe<C, CC>(&mut self, shardchannels: CC) -> PreparedCommand<Self, ()>
    where
        Self: Sized,
        C: SingleArg,
        CC: SingleArgCollection<C>,
    {
        prepare_command(self, cmd("SUNSUBSCRIBE").arg(shardchannels))
    }

    /// Unsubscribes the client from the given channels, or from all of them if none is given.
    ///
    /// # See Also
    /// [<https://redis.io/commands/unsubscribe/>](https://redis.io/commands/unsubscribe/)            
    fn unsubscribe<C, CC>(&mut self, channels: CC) -> PreparedCommand<Self, ()>
    where
        Self: Sized,
        C: SingleArg,
        CC: SingleArgCollection<C>,
    {
        prepare_command(self, cmd("UNSUBSCRIBE").arg(channels))
    }
}