pub struct Builder { /* private fields */ }Expand description
A client and pool builder interface.
fn example() -> Result<(), RedisError> {
// use default values
let client = Builder::default_centralized().build()?;
// or initialize from a URL or config
let config = RedisConfig::from_url("redis://localhost:6379/1")?;
let mut builder = Builder::from_config(config);
// or modify values in place (creating defaults if needed)
builder
.with_performance_config(|config| {
config.auto_pipeline = true;
})
.with_config(|config| {
config.version = RespVersion::RESP3;
config.fail_fast = true;
})
.with_connection_config(|config| {
config.tcp = TcpConfig {
nodelay: Some(true),
..Default::default()
};
config.internal_command_timeout = Duration::from_secs(10);
});
// or overwrite configuration structs in place
builder.set_policy(ReconnectPolicy::new_exponential(0, 100, 30_000, 2));
builder.set_performance_config(PerformanceConfig::default());
// reuse the builder as needed to create any kind of client
let client = builder.build()?;
let pool = builder.build_pool(3)?;
let subscriber = builder.build_subscriber_client()?;
// ...
Ok(())
}Implementations§
source§impl Builder
impl Builder
sourcepub fn default_centralized() -> Self
pub fn default_centralized() -> Self
Create a new builder instance with default config values for a centralized deployment.
sourcepub fn default_clustered() -> Self
pub fn default_clustered() -> Self
Create a new builder instance with default config values for a clustered deployment.
sourcepub fn from_config(config: RedisConfig) -> Self
pub fn from_config(config: RedisConfig) -> Self
Create a new builder instance from the provided client config.
sourcepub fn get_config(&self) -> Option<&RedisConfig>
pub fn get_config(&self) -> Option<&RedisConfig>
Read the client config.
sourcepub fn get_policy(&self) -> Option<&ReconnectPolicy>
pub fn get_policy(&self) -> Option<&ReconnectPolicy>
Read the reconnection policy.
sourcepub fn get_performance_config(&self) -> &PerformanceConfig
pub fn get_performance_config(&self) -> &PerformanceConfig
Read the performance config.
sourcepub fn get_connection_config(&self) -> &ConnectionConfig
pub fn get_connection_config(&self) -> &ConnectionConfig
Read the connection config.
sourcepub fn get_sentinel_config(&self) -> Option<&RedisConfig>
Available on crate feature sentinel-client only.
pub fn get_sentinel_config(&self) -> Option<&RedisConfig>
sentinel-client only.Read the sentinel client config.
sourcepub fn set_config(&mut self, config: RedisConfig) -> &mut Self
pub fn set_config(&mut self, config: RedisConfig) -> &mut Self
Overwrite the client config on the builder.
sourcepub fn set_policy(&mut self, policy: ReconnectPolicy) -> &mut Self
pub fn set_policy(&mut self, policy: ReconnectPolicy) -> &mut Self
Overwrite the reconnection policy on the builder.
sourcepub fn set_performance_config(&mut self, config: PerformanceConfig) -> &mut Self
pub fn set_performance_config(&mut self, config: PerformanceConfig) -> &mut Self
Overwrite the performance config on the builder.
sourcepub fn set_connection_config(&mut self, config: ConnectionConfig) -> &mut Self
pub fn set_connection_config(&mut self, config: ConnectionConfig) -> &mut Self
Overwrite the connection config on the builder.
sourcepub fn set_sentinel_config(&mut self, config: SentinelConfig) -> &mut Self
Available on crate feature sentinel-client only.
pub fn set_sentinel_config(&mut self, config: SentinelConfig) -> &mut Self
sentinel-client only.Overwrite the sentinel config on the builder.
sourcepub fn with_config<F>(&mut self, func: F) -> &mut Selfwhere
F: FnOnce(&mut RedisConfig),
pub fn with_config<F>(&mut self, func: F) -> &mut Selfwhere
F: FnOnce(&mut RedisConfig),
Modify the client config in place, creating a new one with default centralized values first if needed.
sourcepub fn with_performance_config<F>(&mut self, func: F) -> &mut Selfwhere
F: FnOnce(&mut PerformanceConfig),
pub fn with_performance_config<F>(&mut self, func: F) -> &mut Selfwhere
F: FnOnce(&mut PerformanceConfig),
Modify the performance config in place, creating a new one with default values first if needed.
sourcepub fn with_connection_config<F>(&mut self, func: F) -> &mut Selfwhere
F: FnOnce(&mut ConnectionConfig),
pub fn with_connection_config<F>(&mut self, func: F) -> &mut Selfwhere
F: FnOnce(&mut ConnectionConfig),
Modify the connection config in place, creating a new one with default values first if needed.
sourcepub fn with_sentinel_config<F>(&mut self, func: F) -> &mut Selfwhere
F: FnOnce(&mut SentinelConfig),
Available on crate feature sentinel-client only.
pub fn with_sentinel_config<F>(&mut self, func: F) -> &mut Selfwhere
F: FnOnce(&mut SentinelConfig),
sentinel-client only.Modify the sentinel config in place, creating a new one with default values first if needed.
sourcepub fn build(&self) -> Result<RedisClient, RedisError>
pub fn build(&self) -> Result<RedisClient, RedisError>
Create a new client.
sourcepub fn build_pool(&self, size: usize) -> Result<RedisPool, RedisError>
pub fn build_pool(&self, size: usize) -> Result<RedisPool, RedisError>
Create a new client pool.
sourcepub fn build_subscriber_client(&self) -> Result<SubscriberClient, RedisError>
Available on crate feature subscriber-client only.
pub fn build_subscriber_client(&self) -> Result<SubscriberClient, RedisError>
subscriber-client only.Create a new subscriber client.
sourcepub fn build_sentinel_client(&self) -> Result<SentinelClient, RedisError>
Available on crate feature sentinel-client only.
pub fn build_sentinel_client(&self) -> Result<SentinelClient, RedisError>
sentinel-client only.Create a new sentinel client.
This is only necessary if callers need to communicate directly with sentinel nodes. Use a
ServerConfig::Sentinel to interact with Redis servers behind a sentinel layer.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Builder
impl !RefUnwindSafe for Builder
impl !Send for Builder
impl !Sync for Builder
impl Unpin for Builder
impl !UnwindSafe for Builder
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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