Skip to main content

Connection

Struct Connection 

Source
pub struct Connection<T> { /* private fields */ }
Expand description

A stateful connection to the Redis server.

Implementations§

Source§

impl<T: AsyncRead + AsyncWrite + Unpin> Connection<T>

Source

pub async fn new(transport: T) -> Result<(Self, Value), Error>

Connect to the Redis server using the transport.

On success, returns the Connection and HELLO command’s response as a Value which contains the server’s metadata.

Source

pub async fn with_args( transport: T, auth: Option<(&str, &str)>, setname: Option<&str>, select: Option<u32>, ) -> Result<(Self, Value), Error>

Connects to the Redis server using the transport and parameters. See the Builder’s methods for the usage of each parameter.

Source

pub async fn send<Req: Serialize>(&mut self, request: Req) -> Result<u64, Error>

Sends a command without waiting for a response.

Returns a one-based index of the command sent from this connection.

Source

pub async fn wait_response(&mut self) -> Result<Option<u64>, Error>

Wait until a response arrives.

Returns an optional one-based index of the response arrived from this connection. This index can be useful for matching a command and its corresponding response.

The index is None for the Push message since it does not have a corresponding command.

It’s guaranteed that .message() returns Some(msg) after this method returns Ok(idx).

Source

pub fn response(&self) -> Option<Message<'_>>

Get the last response received.

Source

pub async fn raw_command<'de, Req: Serialize, Resp: Deserialize<'de>>( &'de mut self, request: Req, ) -> Result<Resp, Error>

Sends any command and get a response.

Both command and response are serialized/deserialized using serde. See CommandSerializer and Deserializer for details.

Returned response may contain a reference to the connection’s internal receive buffer.

Source

pub fn split(self) -> (ConnectionSendHalf<T>, ConnectionReceiveHalf<T>)

Splits the connection into send/receive halves. Can be used as a building block for higher abstractions.

Trait Implementations§

Source§

impl<T: Debug> Debug for Connection<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: AsyncRead + AsyncWrite + Send + Unpin> RawCommandMut for Connection<T>

Source§

fn raw_command<'de, Req, Resp>( &'de mut self, request: Req, ) -> BoxFuture<'de, Result<Resp, Error>>
where Req: Serialize + Send + 'de, Resp: Deserialize<'de> + 'de,

Sends any command and get a response. Read more
Source§

fn command(self) -> CommandHelper<Mutex<Self>>
where Self: Sized,

Wraps self to allow calling helper methods.

Auto Trait Implementations§

§

impl<T> Freeze for Connection<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Connection<T>
where T: RefUnwindSafe,

§

impl<T> Send for Connection<T>
where T: Send,

§

impl<T> Sync for Connection<T>
where T: Sync,

§

impl<T> Unpin for Connection<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Connection<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Connection<T>
where T: UnwindSafe,

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, 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<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.