pub struct RedisBroker { /* private fields */ }Expand description
An unconnected Redis broker: the recorded topology and its options, no I/O performed yet.
Build it with standalone, cluster,
sentinel, or from_pool. All four are synchronous and
perform no I/O, so a Redis service composes with the synchronous #[ruststream::app] builder;
the runtime dials once at startup through the consuming Broker::connect, which yields the
ConnectedRedisBroker every subscription and publisher is reached from.
§Examples
use ruststream::{Broker, ConnectedBroker};
use ruststream_fred::{RedisBroker, RedisStream};
let connected = RedisBroker::standalone("redis://localhost:6379").connect().await?;
let publisher = connected.publisher();
let sub = connected.subscribe(RedisStream::new("orders").group("workers")).await?;
let _closed = connected.shutdown().await?;Implementations§
Source§impl RedisBroker
impl RedisBroker
Sourcepub fn standalone(url: impl Into<String>) -> Self
pub fn standalone(url: impl Into<String>) -> Self
Creates a standalone-topology broker that connects to url when Broker::connect runs.
Sourcepub fn cluster(nodes: impl IntoIterator<Item = impl Into<String>>) -> Self
pub fn cluster(nodes: impl IntoIterator<Item = impl Into<String>>) -> Self
Creates a Redis Cluster broker from one or more host:port seed nodes.
Only one reachable node is needed; fred discovers the rest of the cluster on connect.
Sourcepub fn sentinel(
service: impl Into<String>,
sentinels: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn sentinel( service: impl Into<String>, sentinels: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Creates a Sentinel-backed broker that tracks the primary named service, discovering it
through the given sentinel host:port addresses.
Sourcepub fn from_pool(pool: Pool) -> Self
pub fn from_pool(pool: Pool) -> Self
Wraps an already-connected fred pool. Useful for advanced configuration (TLS, cluster,
sentinel, custom performance and reconnection policies).
Broker::connect adopts the pool instead of dialing; the config it was built from is
reused for the dedicated clients Pub/Sub subscriptions need.
Sourcepub fn default_group(self, group: impl Into<String>) -> Self
pub fn default_group(self, group: impl Into<String>) -> Self
Sets a broker-wide default consumer group, enabling the bare-string #[subscriber("key")]
form (Redis Streams always read through a group). Without it a bare-string subscription
returns RedisError::InvalidOptions; name the group per subscription with
RedisStream::group instead.
Sourcepub fn credentials(
self,
username: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn credentials( self, username: impl Into<String>, password: impl Into<String>, ) -> Self
Sets the ACL username and password used to authenticate on connect, applied on every
topology (standalone, cluster, sentinel).
This maps onto fred’s Config.username / Config.password, so authentication works
beyond the standalone redis://user:pass@host URL, which the bare cluster / sentinel
seed lists cannot express. Credentials set here override any in a standalone URL.
For a password-only AUTH (the legacy requirepass, no ACL user) use
password.
§Examples
use ruststream_fred::RedisBroker;
let broker = RedisBroker::cluster(["10.0.0.1:6379"]).credentials("worker", "s3cr3t");Sourcepub fn password(self, password: impl Into<String>) -> Self
pub fn password(self, password: impl Into<String>) -> Self
Sets a password-only AUTH (no ACL username; the legacy requirepass form), on every
topology. Use credentials for an ACL user plus password.
§Examples
use ruststream_fred::RedisBroker;
let broker = RedisBroker::sentinel("mymaster", ["10.0.0.1:26379"]).password("s3cr3t");Sourcepub fn tls(self, tls: impl Into<TlsConfig>) -> Self
pub fn tls(self, tls: impl Into<TlsConfig>) -> Self
Sets the TLS configuration used on connect, on every topology. Accepts a fred
TlsConfig or anything convertible into one (for example a TlsConnector).
Available behind the tls-rustls, tls-rustls-ring, or tls-native-tls feature; a
standalone broker can also enable TLS through a rediss:// / valkeys:// URL. The
fred re-exports TlsConfig / TlsConnector
provide default_rustls() / default_native_tls() shorthands for system-trust setups.
§Examples
use ruststream_fred::{RedisBroker, TlsConfig};
fn build(tls: TlsConfig) -> RedisBroker {
RedisBroker::cluster(["10.0.0.1:6379"]).tls(tls)
}Sourcepub fn sentinel_credentials(
self,
username: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn sentinel_credentials( self, username: impl Into<String>, password: impl Into<String>, ) -> Self
Sets distinct credentials for authenticating to the sentinel nodes, separate from the
data-node credentials. Only meaningful on the sentinel topology.
Available behind the sentinel-auth feature.
§Examples
use ruststream_fred::RedisBroker;
let broker = RedisBroker::sentinel("mymaster", ["10.0.0.1:26379"])
.credentials("worker", "data-pass")
.sentinel_credentials("sentinel-user", "sentinel-pass");Sourcepub fn sentinel_password(self, password: impl Into<String>) -> Self
pub fn sentinel_password(self, password: impl Into<String>) -> Self
Sets a password-only credential for authenticating to the sentinel nodes. Use
sentinel_credentials for an ACL user plus password.
Available behind the sentinel-auth feature.
§Examples
use ruststream_fred::RedisBroker;
let broker = RedisBroker::sentinel("mymaster", ["10.0.0.1:26379"])
.sentinel_password("sentinel-pass");Sourcepub fn credential_provider(self, provider: Arc<dyn CredentialProvider>) -> Self
pub fn credential_provider(self, provider: Arc<dyn CredentialProvider>) -> Self
Sets a dynamic credential provider that supplies (and can rotate) the username/password on
each AUTH / HELLO, for IAM-style auth. Takes precedence over static
credentials.
Available behind the credential-provider feature.
§Examples
use std::sync::Arc;
use ruststream_fred::{CredentialProvider, RedisBroker};
fn build(provider: Arc<dyn CredentialProvider>) -> RedisBroker {
RedisBroker::standalone("redis://localhost:6379").credential_provider(provider)
}Trait Implementations§
Source§impl Broker for RedisBroker
impl Broker for RedisBroker
Source§async fn connect(self) -> Result<Self::Connected, Self::Error>
async fn connect(self) -> Result<Self::Connected, Self::Error>
Opens (or adopts) the connection pool, consuming the unconnected form.
§Errors
Returns RedisError::Connect when the recorded topology cannot be turned into a fred
config or the pool cannot reach the server.
Source§type Error = RedisError
type Error = RedisError
Source§type Connected = ConnectedRedisBroker
type Connected = ConnectedRedisBroker
connect
succeeded.Source§impl Clone for RedisBroker
impl Clone for RedisBroker
Source§fn clone(&self) -> RedisBroker
fn clone(&self) -> RedisBroker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RedisBroker
impl Debug for RedisBroker
Source§impl DescribeServer for RedisBroker
DescribeServer reports the configured Redis address (the first seed for cluster/sentinel).
impl DescribeServer for RedisBroker
DescribeServer reports the configured Redis address (the first seed for cluster/sentinel).
Source§fn describe_server(&self) -> ServerSpec
fn describe_server(&self) -> ServerSpec
Auto Trait Implementations§
impl !RefUnwindSafe for RedisBroker
impl !UnwindSafe for RedisBroker
impl Freeze for RedisBroker
impl Send for RedisBroker
impl Sync for RedisBroker
impl Unpin for RedisBroker
impl UnsafeUnpin for RedisBroker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<B> BrokerRegistration for Bwhere
B: Broker + 'static,
impl<B> BrokerRegistration for Bwhere
B: Broker + 'static,
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more