pub struct SentinelClient { /* private fields */ }sentinel only.Expand description
A utility wrapping Sentinel with an interface similar to Client.
Uses the Sentinel type internally. This is a utility to help make it easier
to use sentinels but with an interface similar to the client (get_connection and
get_async_connection). The type of server (master or replica) and name of the
desired master are specified when constructing an instance, so it will always
return connections to the same target (for example, always to the master with name
“mymaster123”, or always to replicas of the master “another-master-abc”).
Implementations§
Source§impl SentinelClient
impl SentinelClient
Sourcepub fn build<T: IntoConnectionInfo>(
params: Vec<T>,
service_name: impl AsRef<str>,
node_connection_info: Option<SentinelNodeConnectionInfo>,
server_type: SentinelServerType,
) -> RedisResult<Self>
Available on crate feature tls-rustls only.
pub fn build<T: IntoConnectionInfo>( params: Vec<T>, service_name: impl AsRef<str>, node_connection_info: Option<SentinelNodeConnectionInfo>, server_type: SentinelServerType, ) -> RedisResult<Self>
tls-rustls only.Creates a SentinelClient performing some basic checks on the URLs that might result in an error.
Sourcepub fn get_client(&mut self) -> RedisResult<Client>
pub fn get_client(&mut self) -> RedisResult<Client>
Returns a Client considering the server type.
Sourcepub fn get_sentinel_client(&mut self) -> RedisResult<Client>
pub fn get_sentinel_client(&mut self) -> RedisResult<Client>
Returns a Client connected to the first Sentinel node that
responds successfully to ROLE with the expected value.
The function walks through the list supplied in
Sentinel::sentinels_connection_info, trying each address in order:
- Client::open attempts to build a client for that Sentinel.
- We immediately issue
ROLEto confirm the node is reachable and is a Setinel node. - The first node that passes both checks, the client is returned.
If none of the Sentinel addresses respond successfully or, an error occurs when establishing a connection, the method returns the appropriate error.
Use this client when you need Sentinel-specific features—e.g.
subscribing to +switch-master Pub/Sub events or running topology
queries—rather than talking to the Redis master itself.
Sourcepub fn get_connection(&mut self) -> RedisResult<Connection>
pub fn get_connection(&mut self) -> RedisResult<Connection>
Creates a new connection to the desired type of server (based on the service/master name, and the server type). We use a Sentinel to create a client for the target type of server, and then create a connection using that client.
Source§impl SentinelClient
To enable async support you need to chose one of the supported runtimes and active its
corresponding feature: tokio-comp or smol-comp
impl SentinelClient
To enable async support you need to chose one of the supported runtimes and active its
corresponding feature: tokio-comp or smol-comp
Sourcepub async fn async_get_client(&mut self) -> RedisResult<Client>
Available on crate feature aio only.
pub async fn async_get_client(&mut self) -> RedisResult<Client>
aio only.Returns a Client considering the server type.
Sourcepub async fn async_get_sentinel_client(&mut self) -> RedisResult<Client>
Available on crate feature aio only.
pub async fn async_get_sentinel_client(&mut self) -> RedisResult<Client>
aio only.Returns a Client connected to the first Sentinel node that
responds successfully to ROLE with the expected value.
The function walks through the list supplied in
Sentinel::sentinels_connection_info, trying each address in order:
Client::openattempts to build a client for that Sentinel.- We immediately issue
ROLEto confirm the node is reachable and is a Setinel node. - The first node that passes both checks, the client is returned.
If none of the Sentinel addresses respond successfully or, an error occurs when establishing a connection, the method returns the appropriate error.
Use this client when you need Sentinel-specific features—e.g.
subscribing to +switch-master Pub/Sub events or running topology
queries—rather than talking to the Redis master itself.
Sourcepub async fn get_async_connection(&mut self) -> RedisResult<AsyncConnection>
Available on crate feature aio only.
pub async fn get_async_connection(&mut self) -> RedisResult<AsyncConnection>
aio only.Returns an async connection from the client, using the same logic from
SentinelClient::get_connection.
Sourcepub async fn get_async_connection_with_config(
&mut self,
config: &AsyncConnectionConfig,
) -> RedisResult<AsyncConnection>
Available on crate feature aio only.
pub async fn get_async_connection_with_config( &mut self, config: &AsyncConnectionConfig, ) -> RedisResult<AsyncConnection>
aio only.Returns an async connection from the client with options, using the same logic from
SentinelClient::get_connection.