Skip to content

Commit

Permalink
Clarify RESP3 subscription documentation.
Browse files Browse the repository at this point in the history
This hopefully helps clarify some of the issues raised in redis-rs#1435
  • Loading branch information
nihohit committed Dec 2, 2024
1 parent bc8b4f7 commit 66752cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
18 changes: 17 additions & 1 deletion redis/src/aio/connection_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ impl ConnectionManagerConfig {
self
}

/// Sets sender channel for push values. Will fail client creation if the connection isn't configured for RESP3 communications.
/// Sets sender channel for push values.
///
/// This will fail client creation if the connection isn't configured for RESP3 communications via the [RedisConnectionInfo::protocol] field.
pub fn set_push_sender(mut self, sender: AsyncPushSender) -> Self {
self.push_sender = Some(sender);
self
Expand Down Expand Up @@ -391,6 +393,11 @@ impl ConnectionManager {
}

/// Subscribes to a new channel.
///
/// Updates from the sender will be sent on the push sender that was passed to the manager.
/// If the manager was configured without a push sender, the connection won't be able to pass messages back to the user..
///
/// This method is only available when the connection is using RESP3 protocol, and will return an error otherwise.
/// It should be noted that the subscription will be removed on a disconnect and must be re-subscribed.
pub async fn subscribe(&mut self, channel_name: impl ToRedisArgs) -> RedisResult<()> {
check_resp3!(self.client.connection_info.redis.protocol);
Expand All @@ -401,6 +408,8 @@ impl ConnectionManager {
}

/// Unsubscribes from channel.
///
/// This method is only available when the connection is using RESP3 protocol, and will return an error otherwise.
pub async fn unsubscribe(&mut self, channel_name: impl ToRedisArgs) -> RedisResult<()> {
check_resp3!(self.client.connection_info.redis.protocol);
let mut cmd = cmd("UNSUBSCRIBE");
Expand All @@ -410,6 +419,11 @@ impl ConnectionManager {
}

/// Subscribes to a new channel with pattern.
///
/// Updates from the sender will be sent on the push sender that was passed to the manager.
/// If the manager was configured without a push sender, the manager won't be able to pass messages back to the user..
///
/// This method is only available when the connection is using RESP3 protocol, and will return an error otherwise.
/// It should be noted that the subscription will be removed on a disconnect and must be re-subscribed.
pub async fn psubscribe(&mut self, channel_pattern: impl ToRedisArgs) -> RedisResult<()> {
check_resp3!(self.client.connection_info.redis.protocol);
Expand All @@ -420,6 +434,8 @@ impl ConnectionManager {
}

/// Unsubscribes from channel pattern.
///
/// This method is only available when the connection is using RESP3 protocol, and will return an error otherwise.
pub async fn punsubscribe(&mut self, channel_pattern: impl ToRedisArgs) -> RedisResult<()> {
check_resp3!(self.client.connection_info.redis.protocol);
let mut cmd = cmd("PUNSUBSCRIBE");
Expand Down
14 changes: 14 additions & 0 deletions redis/src/aio/multiplexed_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ impl ConnectionLike for MultiplexedConnection {

impl MultiplexedConnection {
/// Subscribes to a new channel.
///
/// Updates from the sender will be sent on the push sender that was passed to the connection.
/// If the connection was configured without a push sender, the connection won't be able to pass messages back to the user..
///
/// This method is only available when the connection is using RESP3 protocol, and will return an error otherwise.
pub async fn subscribe(&mut self, channel_name: impl ToRedisArgs) -> RedisResult<()> {
check_resp3!(self.protocol);
let mut cmd = cmd("SUBSCRIBE");
Expand All @@ -601,6 +606,8 @@ impl MultiplexedConnection {
}

/// Unsubscribes from channel.
///
/// This method is only available when the connection is using RESP3 protocol, and will return an error otherwise.
pub async fn unsubscribe(&mut self, channel_name: impl ToRedisArgs) -> RedisResult<()> {
check_resp3!(self.protocol);
let mut cmd = cmd("UNSUBSCRIBE");
Expand All @@ -610,6 +617,11 @@ impl MultiplexedConnection {
}

/// Subscribes to a new channel with pattern.
///
/// Updates from the sender will be sent on the push sender that was passed to the connection.
/// If the connection was configured without a push sender, the connection won't be able to pass messages back to the user..
///
/// This method is only available when the connection is using RESP3 protocol, and will return an error otherwise.
pub async fn psubscribe(&mut self, channel_pattern: impl ToRedisArgs) -> RedisResult<()> {
check_resp3!(self.protocol);
let mut cmd = cmd("PSUBSCRIBE");
Expand All @@ -619,6 +631,8 @@ impl MultiplexedConnection {
}

/// Unsubscribes from channel pattern.
///
/// This method is only available when the connection is using RESP3 protocol, and will return an error otherwise.
pub async fn punsubscribe(&mut self, channel_pattern: impl ToRedisArgs) -> RedisResult<()> {
check_resp3!(self.protocol);
let mut cmd = cmd("PUNSUBSCRIBE");
Expand Down
4 changes: 3 additions & 1 deletion redis/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ impl AsyncConnectionConfig {
self
}

/// Sets sender channel for push values. Will fail client creation if the connection isn't configured for RESP3 communications.
/// Sets sender channel for push values.
///
/// This will fail client creation if the connection isn't configured for RESP3 communications via the [RedisConnectionInfo::protocol] field.
pub fn set_push_sender(mut self, sender: AsyncPushSender) -> Self {
self.push_sender = Some(sender);
self
Expand Down

0 comments on commit 66752cd

Please sign in to comment.