pub struct Connection<T> { /* private fields */ }Expand description
A stateful connection to the Redis server.
Implementations§
Source§impl<T: AsyncRead + AsyncWrite + Unpin> Connection<T>
impl<T: AsyncRead + AsyncWrite + Unpin> Connection<T>
Sourcepub async fn new(transport: T) -> Result<(Self, Value), Error>
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.
Sourcepub async fn with_args(
transport: T,
auth: Option<(&str, &str)>,
setname: Option<&str>,
select: Option<u32>,
) -> Result<(Self, Value), Error>
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.
Sourcepub async fn send<Req: Serialize>(&mut self, request: Req) -> Result<u64, Error>
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.
Sourcepub async fn wait_response(&mut self) -> Result<Option<u64>, Error>
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).
Sourcepub async fn raw_command<'de, Req: Serialize, Resp: Deserialize<'de>>(
&'de mut self,
request: Req,
) -> Result<Resp, Error>
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.
Sourcepub fn split(self) -> (ConnectionSendHalf<T>, ConnectionReceiveHalf<T>)
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.