Trait fred::interfaces::ClientLike

source ·
pub trait ClientLike: Clone + Sized {
Show 29 methods // Provided methods fn id(&self) -> &str { ... } fn client_config(&self) -> RedisConfig { ... } fn client_reconnect_policy(&self) -> Option<ReconnectPolicy> { ... } fn connection_config(&self) -> &ConnectionConfig { ... } fn protocol_version(&self) -> RespVersion { ... } fn has_reconnect_policy(&self) -> bool { ... } fn is_pipelined(&self) -> bool { ... } fn is_clustered(&self) -> bool { ... } fn uses_sentinels(&self) -> bool { ... } fn update_perf_config(&self, config: PerformanceConfig) { ... } fn perf_config(&self) -> PerformanceConfig { ... } fn state(&self) -> ClientState { ... } fn is_connected(&self) -> bool { ... } fn active_connections( &self, ) -> impl Future<Output = Result<Vec<Server>, RedisError>> { ... } fn server_version(&self) -> Option<Version> { ... } fn set_resolver(&self, resolver: Rc<dyn Resolve>) -> impl Future { ... } fn connect(&self) -> ConnectHandle { ... } fn force_reconnection(&self) -> impl Future<Output = RedisResult<()>> { ... } fn wait_for_connect(&self) -> impl Future<Output = RedisResult<()>> { ... } fn init(&self) -> impl Future<Output = RedisResult<ConnectHandle>> { ... } fn quit(&self) -> impl Future<Output = RedisResult<()>> { ... } fn shutdown( &self, flags: Option<ShutdownFlags>, ) -> impl Future<Output = RedisResult<()>> { ... } fn flushall<R>(&self, async: bool) -> impl Future<Output = RedisResult<R>> where R: FromRedis { ... } fn flushall_cluster(&self) -> impl Future<Output = RedisResult<()>> { ... } fn ping<R>(&self) -> impl Future<Output = RedisResult<R>> where R: FromRedis { ... } fn info<R>( &self, section: Option<InfoKind>, ) -> impl Future<Output = RedisResult<R>> where R: FromRedis { ... } fn custom<R, T>( &self, cmd: CustomCommand, args: Vec<T>, ) -> impl Future<Output = RedisResult<R>> where R: FromRedis, T: TryInto<RedisValue>, T::Error: Into<RedisError> { ... } fn custom_raw<T>( &self, cmd: CustomCommand, args: Vec<T>, ) -> impl Future<Output = RedisResult<Resp3Frame>> where T: TryInto<RedisValue>, T::Error: Into<RedisError> { ... } fn with_options(&self, options: &Options) -> WithOptions<Self> { ... }
}

Provided Methods§

source

fn id(&self) -> &str

The unique ID identifying this client and underlying connections.

source

fn client_config(&self) -> RedisConfig

Read the config used to initialize the client.

source

fn client_reconnect_policy(&self) -> Option<ReconnectPolicy>

Read the reconnect policy used to initialize the client.

source

fn connection_config(&self) -> &ConnectionConfig

Read the connection config used to initialize the client.

source

fn protocol_version(&self) -> RespVersion

Read the RESP version used by the client when communicating with the server.

source

fn has_reconnect_policy(&self) -> bool

Whether the client has a reconnection policy.

source

fn is_pipelined(&self) -> bool

Whether the client will automatically pipeline commands.

source

fn is_clustered(&self) -> bool

Whether the client is connected to a cluster.

source

fn uses_sentinels(&self) -> bool

Whether the client uses the sentinel interface.

source

fn update_perf_config(&self, config: PerformanceConfig)

Update the internal PerformanceConfig in place with new values.

source

fn perf_config(&self) -> PerformanceConfig

Read the PerformanceConfig associated with this client.

source

fn state(&self) -> ClientState

Read the state of the underlying connection(s).

If running against a cluster the underlying state will reflect the state of the least healthy connection.

source

fn is_connected(&self) -> bool

Whether all underlying connections are healthy.

source

fn active_connections( &self, ) -> impl Future<Output = Result<Vec<Server>, RedisError>>

Read the set of active connections managed by the client.

source

fn server_version(&self) -> Option<Version>

Read the server version, if known.

source

fn set_resolver(&self, resolver: Rc<dyn Resolve>) -> impl Future

Available on crate feature dns only.

Override the DNS resolution logic for the client.

source

fn connect(&self) -> ConnectHandle

Connect to the server.

This function returns a JoinHandle to a task that drives the connection. It will not resolve until the connection closes, or if a reconnection policy with unlimited attempts is provided then it will run until QUIT is called. Callers should avoid calling abort on the returned JoinHandle unless the client will no longer be used.

Calling this function more than once will drop all state associated with the previous connection(s). Any pending commands on the old connection(s) will either finish or timeout, but they will not be retried on the new connection(s).

See init for an alternative shorthand.

source

fn force_reconnection(&self) -> impl Future<Output = RedisResult<()>>

Force a reconnection to the server(s).

When running against a cluster this function will also refresh the cached cluster routing table.

source

fn wait_for_connect(&self) -> impl Future<Output = RedisResult<()>>

Wait for the result of the next connection attempt.

This can be used with on_reconnect to separate initialization logic that needs to occur only on the next connection attempt vs all subsequent attempts.

source

fn init(&self) -> impl Future<Output = RedisResult<ConnectHandle>>

Initialize a new routing and connection task and wait for it to connect successfully.

The returned ConnectHandle refers to the task that drives the routing and connection layer. It will not finish until the max reconnection count is reached. Callers should avoid calling abort on the returned JoinHandle unless the client will no longer be used.

Callers can also use connect and wait_for_connect separately if needed.

use fred::prelude::*;

#[tokio::main]
async fn main() -> Result<(), RedisError> {
  let client = RedisClient::default();
  let connection_task = client.init().await?;

  // ...

  client.quit().await?;
  connection_task.await?
}
source

fn quit(&self) -> impl Future<Output = RedisResult<()>>

Close the connection to the Redis server. The returned future resolves when the command has been written to the socket, not when the connection has been fully closed. Some time after this future resolves the future returned by connect will resolve which indicates that the connection has been fully closed.

This function will also close all error, pubsub message, and reconnection event streams.

source

fn shutdown( &self, flags: Option<ShutdownFlags>, ) -> impl Future<Output = RedisResult<()>>

Available on crate feature i-server only.

Shut down the server and quit the client.

https://redis.io/commands/shutdown

source

fn flushall<R>(&self, async: bool) -> impl Future<Output = RedisResult<R>>
where R: FromRedis,

Delete the keys in all databases.

https://redis.io/commands/flushall

source

fn flushall_cluster(&self) -> impl Future<Output = RedisResult<()>>

Delete the keys on all nodes in the cluster. This is a special function that does not map directly to the Redis interface.

source

fn ping<R>(&self) -> impl Future<Output = RedisResult<R>>
where R: FromRedis,

Ping the Redis server.

https://redis.io/commands/ping

source

fn info<R>( &self, section: Option<InfoKind>, ) -> impl Future<Output = RedisResult<R>>
where R: FromRedis,

Read info about the server.

https://redis.io/commands/info

source

fn custom<R, T>( &self, cmd: CustomCommand, args: Vec<T>, ) -> impl Future<Output = RedisResult<R>>

Run a custom command that is not yet supported via another interface on this client. This is most useful when interacting with third party modules or extensions.

Callers should use the re-exported redis_keyslot function to hash the command’s key, if necessary.

This interface should be used with caution as it may break the automatic pipeline features in the client if command flags are not properly configured.

source

fn custom_raw<T>( &self, cmd: CustomCommand, args: Vec<T>, ) -> impl Future<Output = RedisResult<Resp3Frame>>

Run a custom command similar to custom, but return the response frame directly without any parsing.

Note: RESP2 frames from the server are automatically converted to the RESP3 format when parsed by the client.

source

fn with_options(&self, options: &Options) -> WithOptions<Self>

Customize various configuration options on commands.

Object Safety§

This trait is not object safe.

Implementors§