pub struct PooledConnection { /* private fields */ }Expand description
池中实际持有的连接。
用 epoch 标记它“出生时“的 master 版本号;一旦后台 watcher 检测到 master
变更并 bump_epoch,所有旧连接的
epoch 都会小于当前 epoch,从而在 has_broken / is_valid 中被识别为失效。
Methods from Deref<Target = MultiplexedConnection>§
Sourcepub fn set_response_timeout(&mut self, timeout: Duration)
pub fn set_response_timeout(&mut self, timeout: Duration)
Sets the time that the multiplexer will wait for responses on operations before failing.
Sourcepub async fn send_packed_command(
&mut self,
cmd: &Cmd,
) -> Result<Value, RedisError>
pub async fn send_packed_command( &mut self, cmd: &Cmd, ) -> Result<Value, RedisError>
Sends an already encoded (packed) command into the TCP socket and reads the single response from it.
Sourcepub async fn send_packed_commands(
&mut self,
cmd: &Pipeline,
offset: usize,
count: usize,
) -> Result<Vec<Value>, RedisError>
pub async fn send_packed_commands( &mut self, cmd: &Pipeline, offset: usize, count: usize, ) -> Result<Vec<Value>, RedisError>
Sends multiple already encoded (packed) command into the TCP socket
and reads count responses from it. This is used to implement
pipelining.
Sourcepub async fn subscribe(
&mut self,
channel_name: impl ToRedisArgs,
) -> Result<(), RedisError>
pub async fn subscribe( &mut self, channel_name: impl ToRedisArgs, ) -> Result<(), RedisError>
Subscribes to a new channel(s).
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.
let client = redis::Client::open("redis://127.0.0.1/?protocol=resp3").unwrap();
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
let config = redis::AsyncConnectionConfig::new().set_push_sender(tx);
let mut con = client.get_multiplexed_async_connection_with_config(&config).await?;
con.subscribe(&["channel_1", "channel_2"]).await?;Sourcepub async fn unsubscribe(
&mut self,
channel_name: impl ToRedisArgs,
) -> Result<(), RedisError>
pub async fn unsubscribe( &mut self, channel_name: impl ToRedisArgs, ) -> Result<(), RedisError>
Unsubscribes from channel(s).
This method is only available when the connection is using RESP3 protocol, and will return an error otherwise.
let client = redis::Client::open("redis://127.0.0.1/?protocol=resp3").unwrap();
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
let config = redis::AsyncConnectionConfig::new().set_push_sender(tx);
let mut con = client.get_multiplexed_async_connection_with_config(&config).await?;
con.subscribe(&["channel_1", "channel_2"]).await?;
con.unsubscribe(&["channel_1", "channel_2"]).await?;Sourcepub async fn psubscribe(
&mut self,
channel_pattern: impl ToRedisArgs,
) -> Result<(), RedisError>
pub async fn psubscribe( &mut self, channel_pattern: impl ToRedisArgs, ) -> Result<(), RedisError>
Subscribes to new channel(s) with pattern(s).
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.
let client = redis::Client::open("redis://127.0.0.1/?protocol=resp3").unwrap();
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
let config = redis::AsyncConnectionConfig::new().set_push_sender(tx);
let mut con = client.get_multiplexed_async_connection_with_config(&config).await?;
con.psubscribe("channel*_1").await?;
con.psubscribe(&["channel*_2", "channel*_3"]).await?;Sourcepub async fn punsubscribe(
&mut self,
channel_pattern: impl ToRedisArgs,
) -> Result<(), RedisError>
pub async fn punsubscribe( &mut self, channel_pattern: impl ToRedisArgs, ) -> Result<(), RedisError>
Unsubscribes from channel pattern(s).
This method is only available when the connection is using RESP3 protocol, and will return an error otherwise.