Struct redis::Client

source ·
pub struct Client { /* private fields */ }
Expand description

The client type.

Implementations§

source§

impl Client

The client acts as connector to the redis server. By itself it does not do much other than providing a convenient way to fetch a connection from it. In the future the plan is to provide a connection pool in the client.

When opening a client a URL in the following format should be used:

redis://host:port/db

Example usage::

let client = redis::Client::open("redis://127.0.0.1/").unwrap();
let con = client.get_connection().unwrap();
source

pub fn open<T: IntoConnectionInfo>(params: T) -> RedisResult<Client>

Connects to a redis server and returns a client. This does not actually open a connection yet but it does perform some basic checks on the URL that might make the operation fail.

source

pub fn get_connection(&self) -> RedisResult<Connection>

Instructs the client to actually connect to redis and returns a connection object. The connection object can be used to send commands to the server. This can fail with a variety of errors (like unreachable host) so it’s important that you handle those errors.

source

pub fn get_connection_with_timeout( &self, timeout: Duration ) -> RedisResult<Connection>

Instructs the client to actually connect to redis with specified timeout and returns a connection object. The connection object can be used to send commands to the server. This can fail with a variety of errors (like unreachable host) so it’s important that you handle those errors.

source

pub fn get_connection_info(&self) -> &ConnectionInfo

Returns a reference of client connection info object.

source§

impl Client

To enable async support you need to chose one of the supported runtimes and active its corresponding feature: tokio-comp or async-std-comp

source

pub async fn get_async_connection(&self) -> RedisResult<Connection>

Available on crate feature aio only.

Returns an async connection from the client.

source

pub async fn get_tokio_connection(&self) -> RedisResult<Connection>

Available on crate features aio and tokio-comp only.

Returns an async connection from the client.

source

pub async fn get_async_std_connection(&self) -> RedisResult<Connection>

Available on crate features aio and async-std-comp only.

Returns an async connection from the client.

source

pub async fn get_multiplexed_async_connection( &self ) -> RedisResult<MultiplexedConnection>

Available on crate feature aio and (crate features tokio-comp or async-std-comp) only.

Returns an async connection from the client.

source

pub async fn get_multiplexed_tokio_connection( &self ) -> RedisResult<MultiplexedConnection>

Available on crate features aio and tokio-comp only.

Returns an async multiplexed connection from the client.

A multiplexed connection can be cloned, allowing requests to be be sent concurrently on the same underlying connection (tcp/unix socket).

source

pub async fn get_multiplexed_async_std_connection( &self ) -> RedisResult<MultiplexedConnection>

Available on crate features aio and async-std-comp only.

Returns an async multiplexed connection from the client.

A multiplexed connection can be cloned, allowing requests to be be sent concurrently on the same underlying connection (tcp/unix socket).

source

pub async fn create_multiplexed_tokio_connection( &self ) -> RedisResult<(MultiplexedConnection, impl Future<Output = ()>)>

Available on crate features aio and tokio-comp only.

Returns an async multiplexed connection from the client and a future which must be polled to drive any requests submitted to it (see get_multiplexed_tokio_connection).

A multiplexed connection can be cloned, allowing requests to be be sent concurrently on the same underlying connection (tcp/unix socket).

source

pub async fn create_multiplexed_async_std_connection( &self ) -> RedisResult<(MultiplexedConnection, impl Future<Output = ()>)>

Available on crate features aio and async-std-comp only.

Returns an async multiplexed connection from the client and a future which must be polled to drive any requests submitted to it (see get_multiplexed_tokio_connection).

A multiplexed connection can be cloned, allowing requests to be be sent concurrently on the same underlying connection (tcp/unix socket).

source

pub async fn get_tokio_connection_manager( &self ) -> RedisResult<ConnectionManager>

Available on crate features aio and connection-manager only.

Returns an async ConnectionManager from the client.

The connection manager wraps a MultiplexedConnection. If a command to that connection fails with a connection error, then a new connection is established in the background and the error is returned to the caller.

This means that on connection loss at least one command will fail, but the connection will be re-established automatically if possible. Please refer to the ConnectionManager docs for detailed reconnecting behavior.

A connection manager can be cloned, allowing requests to be be sent concurrently on the same underlying connection (tcp/unix socket).

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl ConnectionLike for Client

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 req_packed_commands( &mut self, cmd: &[u8], offset: usize, count: usize ) -> RedisResult<Vec<Value>>

Sends multiple already encoded (packed) command into the TCP socket and reads count responses from it. This is used to implement pipelining.
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. Read more
source§

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

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

impl Debug for Client

source§

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

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

impl ManageConnection for Client

Available on crate feature r2d2 only.
§

type Connection = Connection

The connection type this manager deals with.
§

type Error = RedisError

The error type returned by Connections.
source§

fn connect(&self) -> Result<Self::Connection, Self::Error>

Attempts to create a new connection.
source§

fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error>

Determines if the connection is still connected to the database. Read more
source§

fn has_broken(&self, conn: &mut Self::Connection) -> bool

Quickly determines if the connection is no longer usable. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

§

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