pub struct CredentialConnectionFactory { /* private fields */ }Expand description
A provider-backed factory for authenticated Redis connections.
Every call fetches credentials, authenticates the fresh connection, and
then negotiates the requested RESP protocol. This setup order matters for
protected servers: negotiating RESP3 before AUTH can produce NOAUTH
and leave an automatic negotiation silently on RESP2.
If Redis rejects the first AUTH with NOAUTH or WRONGPASS, the factory
asks the provider to force_refresh
and retries AUTH once. It never retries user commands.
The factory implements both
ConnectionFactory and
PoolFactory, so the same setup is replayed by
resilient, multiplexed, lazy, and replacement pool connections.
from_url additionally preserves URL transport, database,
and protocol settings while replacing only URL-embedded authentication with
the provider.
§Example
use redis_tower::credentials::{CredentialConnectionFactory, StaticCredentials};
use redis_tower::reconnect::{ReconnectConfig, ResilientConnection};
let factory = CredentialConnectionFactory::new(
"127.0.0.1:6379",
StaticCredentials::password("secret"),
);
let connection = ResilientConnection::new(factory, ReconnectConfig::default()).await?;Implementations§
Source§impl CredentialConnectionFactory
impl CredentialConnectionFactory
Sourcepub fn new(addr: impl Into<String>, provider: impl CredentialProvider) -> Self
pub fn new(addr: impl Into<String>, provider: impl CredentialProvider) -> Self
Create a plain-TCP factory backed by provider.
Create a plain-TCP factory from a shared, type-erased provider.
This constructor lets several topology or pool factories share one provider cache and refresh state.
Sourcepub fn from_url(
url: impl Into<String>,
provider: impl CredentialProvider,
) -> Self
pub fn from_url( url: impl Into<String>, provider: impl CredentialProvider, ) -> Self
Create a URL-backed factory that authenticates with provider.
TCP, TLS, Unix-socket, database, and protocol URL settings are
preserved. Any username or password embedded in the URL is ignored;
the provider is the single authentication source. Use
RedisConnection::connect_url when static URL credentials are
desired instead.
Create a URL-backed factory from a shared, type-erased provider.
Sourcepub fn with_connection_config(self, config: ConnectionConfig) -> Self
pub fn with_connection_config(self, config: ConnectionConfig) -> Self
Apply connection settings to every initial connection and reconnect.
Keepalive, connect timeout, and RESP decode limits apply during the initial RESP2 bootstrap. The requested protocol is negotiated only after authentication succeeds.
Sourcepub fn with_setup_timeout(self, timeout: Duration) -> Self
pub fn with_setup_timeout(self, timeout: Duration) -> Self
Bound the complete provider-backed setup sequence.
Unlike ConnectionConfig::connect_timeout, which covers only the
socket connect operation, this deadline includes credential lookup,
transport and TLS establishment, bounded refresh-on-rejection, database
selection, and RESP negotiation. Expiry returns
RedisError::ConnectTimeout and drops the partial socket.
Sourcepub fn with_tls(self, hostname: impl Into<String>, tls: TlsConfig) -> Self
Available on crate features tls-native-tls or tls-rustls only.
pub fn with_tls(self, hostname: impl Into<String>, tls: TlsConfig) -> Self
tls-native-tls or tls-rustls only.Use explicit TLS settings for every connection made by this factory.
For address targets, hostname is the server name used for certificate
verification. URL targets use the URL host, matching
RedisConnection::connect_url_with_tls.
Sourcepub fn provider(&self) -> &dyn CredentialProvider
pub fn provider(&self) -> &dyn CredentialProvider
Return the shared credential provider used by this factory.
Clone the shared provider allocation used by this factory.
This is useful when one type-erased provider must also be passed to a Cluster builder or a dedicated-session factory.
Trait Implementations§
Source§impl Clone for CredentialConnectionFactory
impl Clone for CredentialConnectionFactory
Source§impl ConnectionFactory for CredentialConnectionFactory
impl ConnectionFactory for CredentialConnectionFactory
Source§fn connect(
&self,
) -> Pin<Box<dyn Future<Output = Result<RedisConnection, RedisError>> + Send>>
fn connect( &self, ) -> Pin<Box<dyn Future<Output = Result<RedisConnection, RedisError>> + Send>>
RedisConnection.