Skip to main content

CredentialConnectionFactory

Struct CredentialConnectionFactory 

Source
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

Source

pub fn new(addr: impl Into<String>, provider: impl CredentialProvider) -> Self

Create a plain-TCP factory backed by provider.

Source

pub fn from_shared_provider( addr: impl Into<String>, provider: Arc<dyn CredentialProvider>, ) -> Self

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.

Source

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.

Source

pub fn from_url_with_shared_provider( url: impl Into<String>, provider: Arc<dyn CredentialProvider>, ) -> Self

Create a URL-backed factory from a shared, type-erased provider.

Source

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.

Source

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.

Source

pub fn with_tls(self, hostname: impl Into<String>, tls: TlsConfig) -> Self

Available on crate features 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.

Source

pub fn provider(&self) -> &dyn CredentialProvider

Return the shared credential provider used by this factory.

Source

pub fn shared_provider(&self) -> Arc<dyn CredentialProvider> ⓘ

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ConnectionFactory for CredentialConnectionFactory

Source§

fn connect( &self, ) -> Pin<Box<dyn Future<Output = Result<RedisConnection, RedisError>> + Send>>

Create a new RedisConnection.
Source§

impl PoolFactory for CredentialConnectionFactory

Source§

type Connection = RedisConnection

The connection type this factory creates.
Source§

fn create( &self, ) -> Pin<Box<dyn Future<Output = Result<Self::Connection, RedisError>> + Send>>

Create a new connection.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more