Skip to main content

PooledConnection

Struct PooledConnection 

Source
pub struct PooledConnection { /* private fields */ }
Expand description

池中实际持有的连接。

用 epoch 标记它“出生时“的 master 版本号;一旦后台 watcher 检测到 master 变更并 bump_epoch,所有旧连接的 epoch 都会小于当前 epoch,从而在 has_broken / is_valid 中被识别为失效。

Methods from Deref<Target = MultiplexedConnection>§

Source

pub fn set_response_timeout(&mut self, timeout: Duration)

Sets the time that the multiplexer will wait for responses on operations before failing.

Source

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.

Source

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.

Source

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?;
Source

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?;
Source

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?;
Source

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.

Trait Implementations§

Source§

impl AsMut<MultiplexedConnection> for PooledConnection

Source§

fn as_mut(&mut self) -> &mut MultiplexedConnection

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<MultiplexedConnection> for PooledConnection

Source§

fn as_ref(&self) -> &MultiplexedConnection

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Deref for PooledConnection

Source§

type Target = MultiplexedConnection

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for PooledConnection

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more