pub struct ClusterClientBuilder { /* private fields */ }
cluster
only.Expand description
Used to configure and build a ClusterClient
.
Implementations§
Source§impl ClusterClientBuilder
impl ClusterClientBuilder
Sourcepub fn new<T: IntoConnectionInfo>(
initial_nodes: impl IntoIterator<Item = T>,
) -> ClusterClientBuilder
pub fn new<T: IntoConnectionInfo>( initial_nodes: impl IntoIterator<Item = T>, ) -> ClusterClientBuilder
Creates a new ClusterClientBuilder
with the provided initial_nodes.
This is the same as ClusterClient::builder(initial_nodes)
.
Sourcepub fn build(self) -> RedisResult<ClusterClient>
pub fn build(self) -> RedisResult<ClusterClient>
Creates a new ClusterClient
from the parameters.
This does not create connections to the Redis Cluster, but only performs some basic checks on the initial nodes’ URLs and passwords/usernames.
When the tls-rustls
feature is enabled and TLS credentials are provided, they are set for
each cluster connection.
§Errors
Upon failure to parse initial nodes or if the initial nodes have different passwords or usernames, an error is returned.
Sourcepub fn password(self, password: String) -> ClusterClientBuilder
pub fn password(self, password: String) -> ClusterClientBuilder
Sets password for the new ClusterClient.
Sourcepub fn username(self, username: String) -> ClusterClientBuilder
pub fn username(self, username: String) -> ClusterClientBuilder
Sets username for the new ClusterClient.
Sourcepub fn retries(self, retries: u32) -> ClusterClientBuilder
pub fn retries(self, retries: u32) -> ClusterClientBuilder
Sets number of retries for the new ClusterClient.
Sourcepub fn max_retry_wait(self, max_wait: u64) -> ClusterClientBuilder
pub fn max_retry_wait(self, max_wait: u64) -> ClusterClientBuilder
Sets maximal wait time in millisceonds between retries for the new ClusterClient.
Sourcepub fn min_retry_wait(self, min_wait: u64) -> ClusterClientBuilder
pub fn min_retry_wait(self, min_wait: u64) -> ClusterClientBuilder
Sets minimal wait time in millisceonds between retries for the new ClusterClient.
Sourcepub fn retry_wait_formula(
self,
factor: u64,
exponent_base: u64,
) -> ClusterClientBuilder
pub fn retry_wait_formula( self, factor: u64, exponent_base: u64, ) -> ClusterClientBuilder
Sets the factor and exponent base for the retry wait time. The formula for the wait is rand(min_wait_retry .. min(max_retry_wait , factor * exponent_base ^ retry))ms.
Sourcepub fn tls(self, tls: TlsMode) -> ClusterClientBuilder
pub fn tls(self, tls: TlsMode) -> ClusterClientBuilder
Sets TLS mode for the new ClusterClient.
It is extracted from the first node of initial_nodes if not set.
Sourcepub fn danger_accept_invalid_hostnames(
self,
insecure: bool,
) -> ClusterClientBuilder
pub fn danger_accept_invalid_hostnames( self, insecure: bool, ) -> ClusterClientBuilder
Configure hostname verification when connecting with TLS.
If insecure
is true, this disables hostname verification, while
leaving other aspects of certificate checking enabled. This mode is
similar to what redis-cli
does: TLS connections do check certificates,
but hostname errors are ignored.
§Warning
You should think very carefully before you use this method. If hostname verification is not used, any valid certificate for any site will be trusted for use from any other. This introduces a significant vulnerability to man-in-the-middle attacks.
Sourcepub fn certs(self, certificates: TlsCertificates) -> ClusterClientBuilder
pub fn certs(self, certificates: TlsCertificates) -> ClusterClientBuilder
Sets raw TLS certificates for the new ClusterClient.
When set, enforces the connection must be TLS secured.
All certificates must be provided as byte streams loaded from PEM files their consistency is
checked during build()
call.
certificates
-TlsCertificates
structure containing:-
client_tls
- OptionalClientTlsConfig
containing byte streams forclient_cert
- client’s byte stream containing client certificate in PEM formatclient_key
- client’s byte stream containing private key in PEM format
-
root_cert
- Optional byte stream yielding PEM formatted file for root certificates.
-
If ClientTlsConfig
( cert+key pair ) is not provided, then client-side authentication is not enabled.
If root_cert
is not provided, then system root certificates are used instead.
Sourcepub fn read_from_replicas(self) -> ClusterClientBuilder
pub fn read_from_replicas(self) -> ClusterClientBuilder
Enables reading from replicas for all new connections (default is disabled).
If enabled, then read queries will go to the replica nodes & write queries will go to the primary nodes. If there are no replica nodes, then all queries will go to the primary nodes.
Sourcepub fn connection_timeout(
self,
connection_timeout: Duration,
) -> ClusterClientBuilder
pub fn connection_timeout( self, connection_timeout: Duration, ) -> ClusterClientBuilder
Enables timing out on slow connection time.
If enabled, the cluster will only wait the given time on each connection attempt to each node.
Sourcepub fn response_timeout(
self,
response_timeout: Duration,
) -> ClusterClientBuilder
pub fn response_timeout( self, response_timeout: Duration, ) -> ClusterClientBuilder
Enables timing out on slow responses.
If enabled, the cluster will only wait the given time to each response from each node.
Sourcepub fn use_protocol(self, protocol: ProtocolVersion) -> ClusterClientBuilder
pub fn use_protocol(self, protocol: ProtocolVersion) -> ClusterClientBuilder
Sets the protocol with which the client should communicate with the server.
Sourcepub fn open(self) -> RedisResult<ClusterClient>
👎Deprecated since 0.22.0: Use build()
pub fn open(self) -> RedisResult<ClusterClient>
Use build()
.
Sourcepub fn readonly(self, read_from_replicas: bool) -> ClusterClientBuilder
👎Deprecated since 0.22.0: Use read_from_replicas()
pub fn readonly(self, read_from_replicas: bool) -> ClusterClientBuilder
Use read_from_replicas()
.
Sourcepub fn push_sender(
self,
push_sender: impl AsyncPushSender,
) -> ClusterClientBuilder
pub fn push_sender( self, push_sender: impl AsyncPushSender, ) -> ClusterClientBuilder
Sets sender sender for push values.
The sender can be a channel, or an arbitrary function that handles crate::PushInfo values. This will fail client creation if the connection isn’t configured for RESP3 communications via the crate::RedisConnectionInfo::protocol field.
§Examples
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
let config = ClusterClientBuilder::new(vec!["redis://127.0.0.1:6379/"])
.use_protocol(redis::ProtocolVersion::RESP3)
.push_sender(tx);
let messages = Arc::new(Mutex::new(Vec::new()));
let config = ClusterClientBuilder::new(vec!["redis://127.0.0.1:6379/"])
.use_protocol(redis::ProtocolVersion::RESP3)
.push_sender(move |msg|{
let Ok(mut messages) = messages.lock() else {
return Err(redis::aio::SendError);
};
messages.push(msg);
Ok(())
});
Sourcepub fn tcp_settings(self, tcp_settings: TcpSettings) -> ClusterClientBuilder
pub fn tcp_settings(self, tcp_settings: TcpSettings) -> ClusterClientBuilder
Set the behavior of the underlying TCP connection.
Sourcepub fn async_dns_resolver(
self,
resolver: impl AsyncDNSResolver,
) -> ClusterClientBuilder
pub fn async_dns_resolver( self, resolver: impl AsyncDNSResolver, ) -> ClusterClientBuilder
Set asynchronous DNS resolver for the underlying TCP connection.
The parameter resolver must implement the crate::io::AsyncDNSResolver
trait.