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§
sourcefn client_config(&self) -> RedisConfig
fn client_config(&self) -> RedisConfig
Read the config used to initialize the client.
sourcefn client_reconnect_policy(&self) -> Option<ReconnectPolicy>
fn client_reconnect_policy(&self) -> Option<ReconnectPolicy>
Read the reconnect policy used to initialize the client.
sourcefn connection_config(&self) -> &ConnectionConfig
fn connection_config(&self) -> &ConnectionConfig
Read the connection config used to initialize the client.
sourcefn protocol_version(&self) -> RespVersion
fn protocol_version(&self) -> RespVersion
Read the RESP version used by the client when communicating with the server.
sourcefn has_reconnect_policy(&self) -> bool
fn has_reconnect_policy(&self) -> bool
Whether the client has a reconnection policy.
sourcefn is_pipelined(&self) -> bool
fn is_pipelined(&self) -> bool
Whether the client will automatically pipeline commands.
sourcefn is_clustered(&self) -> bool
fn is_clustered(&self) -> bool
Whether the client is connected to a cluster.
sourcefn uses_sentinels(&self) -> bool
fn uses_sentinels(&self) -> bool
Whether the client uses the sentinel interface.
sourcefn update_perf_config(&self, config: PerformanceConfig)
fn update_perf_config(&self, config: PerformanceConfig)
Update the internal PerformanceConfig in place with new values.
sourcefn perf_config(&self) -> PerformanceConfig
fn perf_config(&self) -> PerformanceConfig
Read the PerformanceConfig associated with this client.
sourcefn state(&self) -> ClientState
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.
sourcefn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Whether all underlying connections are healthy.
sourcefn active_connections(
&self,
) -> impl Future<Output = Result<Vec<Server>, RedisError>>
fn active_connections( &self, ) -> impl Future<Output = Result<Vec<Server>, RedisError>>
Read the set of active connections managed by the client.
sourcefn server_version(&self) -> Option<Version>
fn server_version(&self) -> Option<Version>
Read the server version, if known.
sourcefn set_resolver(&self, resolver: Rc<dyn Resolve>) -> impl Future
Available on crate feature dns only.
fn set_resolver(&self, resolver: Rc<dyn Resolve>) -> impl Future
dns only.Override the DNS resolution logic for the client.
sourcefn connect(&self) -> ConnectHandle
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.
sourcefn force_reconnection(&self) -> impl Future<Output = RedisResult<()>>
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.
sourcefn wait_for_connect(&self) -> impl Future<Output = RedisResult<()>>
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.
sourcefn init(&self) -> impl Future<Output = RedisResult<ConnectHandle>>
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?
}sourcefn quit(&self) -> impl Future<Output = RedisResult<()>>
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.
sourcefn shutdown(
&self,
flags: Option<ShutdownFlags>,
) -> impl Future<Output = RedisResult<()>>
Available on crate feature i-server only.
fn shutdown( &self, flags: Option<ShutdownFlags>, ) -> impl Future<Output = RedisResult<()>>
i-server only.Shut down the server and quit the client.
sourcefn flushall<R>(&self, async: bool) -> impl Future<Output = RedisResult<R>>where
R: FromRedis,
fn flushall<R>(&self, async: bool) -> impl Future<Output = RedisResult<R>>where
R: FromRedis,
Delete the keys in all databases.
sourcefn flushall_cluster(&self) -> impl Future<Output = RedisResult<()>>
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.
sourcefn ping<R>(&self) -> impl Future<Output = RedisResult<R>>where
R: FromRedis,
fn ping<R>(&self) -> impl Future<Output = RedisResult<R>>where
R: FromRedis,
Ping the Redis server.
sourcefn info<R>(
&self,
section: Option<InfoKind>,
) -> impl Future<Output = RedisResult<R>>where
R: FromRedis,
fn info<R>(
&self,
section: Option<InfoKind>,
) -> impl Future<Output = RedisResult<R>>where
R: FromRedis,
Read info about the server.
sourcefn custom<R, T>(
&self,
cmd: CustomCommand,
args: Vec<T>,
) -> impl Future<Output = RedisResult<R>>
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.
sourcefn custom_raw<T>(
&self,
cmd: CustomCommand,
args: Vec<T>,
) -> impl Future<Output = RedisResult<Resp3Frame>>
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.
sourcefn with_options(&self, options: &Options) -> WithOptions<Self>
fn with_options(&self, options: &Options) -> WithOptions<Self>
Customize various configuration options on commands.