ConnectionLike in redis - Rust
Description: Implements the “stateless” part of the connection interface that is used by the different objects in redis-rs.

Skip to main content

## ConnectionLike

# Trait ConnectionLike

Source

    pub trait ConnectionLike {
        // Required methods
        fn req_packed_command(&mut self, cmd: &[u8]) -> RedisResult<Value>;
        fn get_db(&self) -> i64;
        fn check_connection(&mut self) -> bool;
        fn is_open(&self) -> bool;

        // Provided method
        fn req_command(&mut self, cmd: &Cmd) -> RedisResult<Value> { ... }
    }

Expand description

Implements the “stateless” part of the connection interface that is used by the different objects in redis-rs.

Primarily it obviously applies to `Connection` object but also some other objects implement the interface (for instance whole clients or certain redis results).

Generally clients and connections (as well as redis results of those) implement this trait. Actual connections provide more functionality which can be used to implement things like `PubSub` but they also can modify the intrinsic state of the TCP connection. This is not possible with `ConnectionLike` implementors because that functionality is not exposed.

## Required Methods§

Source

#### fn req_packed_command(&mut self, cmd: &[u8]) -> RedisResult<Value>

Sends an already encoded (packed) command into the TCP socket and reads the single response from it.

Source

#### fn get_db(&self) -> i64

Returns the database this connection is bound to. Note that this information might be unreliable because it’s initially cached and also might be incorrect if the connection like object is not actually connected.

Source

#### fn check_connection(&mut self) -> bool

Check that all connections it has are available (`PING` internally).

Source

#### fn is_open(&self) -> bool

Returns the connection status.

The connection is open until any `read` call received an invalid response from the server (most likely a closed or dropped connection, otherwise a Redis protocol error). When using unix sockets the connection is open until writing a command failed with a `BrokenPipe` error.

## Provided Methods§

Source

#### fn req_command(&mut self, cmd: &Cmd) -> RedisResult<Value>

Sends a Cmd into the TCP socket and reads a single response from it.

## Implementors§

Source§

### impl ConnectionLike for Client

Source§

### impl ConnectionLike for Connection

Source§

### impl<C, T> ConnectionLike for T
where C: ConnectionLike, T: DerefMut<Target = C>,

Source§

### impl<C: Connect + ConnectionLike> ConnectionLike for ClusterConnection<C>

Available on crate feature `cluster` only.