Struct redis::Connection
source · pub struct Connection { /* private fields */ }
Expand description
Represents a stateful redis TCP connection.
Implementations§
source§impl Connection
impl Connection
A connection is an object that represents a single redis connection. It provides basic support for sending encoded commands into a redis connection and to read a response from it. It’s bound to a single database and can only be created from the client.
You generally do not much with this object other than passing it to
Cmd
objects.
sourcepub fn send_packed_command(&mut self, cmd: &[u8]) -> RedisResult<()>
pub fn send_packed_command(&mut self, cmd: &[u8]) -> RedisResult<()>
Sends an already encoded (packed) command into the TCP socket and
does not read a response. This is useful for commands like
MONITOR
which yield multiple items. This needs to be used with
care because it changes the state of the connection.
sourcepub fn recv_response(&mut self) -> RedisResult<Value>
pub fn recv_response(&mut self) -> RedisResult<Value>
Fetches a single response from the connection. This is useful
if used in combination with send_packed_command
.
sourcepub fn set_write_timeout(&self, dur: Option<Duration>) -> RedisResult<()>
pub fn set_write_timeout(&self, dur: Option<Duration>) -> RedisResult<()>
Sets the write timeout for the connection.
If the provided value is None
, then send_packed_command
call will
block indefinitely. It is an error to pass the zero Duration
to this
method.
sourcepub fn set_read_timeout(&self, dur: Option<Duration>) -> RedisResult<()>
pub fn set_read_timeout(&self, dur: Option<Duration>) -> RedisResult<()>
Sets the read timeout for the connection.
If the provided value is None
, then recv_response
call will
block indefinitely. It is an error to pass the zero Duration
to this
method.
Trait Implementations§
source§impl ConnectionLike for Connection
impl ConnectionLike for Connection
source§fn req_packed_command(&mut self, cmd: &[u8]) -> RedisResult<Value>
fn req_packed_command(&mut self, cmd: &[u8]) -> RedisResult<Value>
source§fn req_packed_commands(
&mut self,
cmd: &[u8],
offset: usize,
count: usize
) -> RedisResult<Vec<Value>>
fn req_packed_commands(
&mut self,
cmd: &[u8],
offset: usize,
count: usize
) -> RedisResult<Vec<Value>>
count
responses from it. This is used to implement
pipelining.source§fn get_db(&self) -> i64
fn get_db(&self) -> i64
source§fn check_connection(&mut self) -> bool
fn check_connection(&mut self) -> bool
PING
internally).