Struct deadpool_redis::cluster::Config
source · pub struct Config {
pub urls: Option<Vec<String>>,
pub connections: Option<Vec<ConnectionInfo>>,
pub pool: Option<PoolConfig>,
pub read_from_replicas: bool,
}
Expand description
Configuration object.
§Example (from environment)
By enabling the serde
feature you can read the configuration using the
config
crate as following:
REDIS_CLUSTER__URLS=redis://127.0.0.1:7000,redis://127.0.0.1:7001
REDIS_CLUSTER__READ_FROM_REPLICAS=true
REDIS_CLUSTER__POOL__MAX_SIZE=16
REDIS_CLUSTER__POOL__TIMEOUTS__WAIT__SECS=2
REDIS_CLUSTER__POOL__TIMEOUTS__WAIT__NANOS=0
#[derive(serde::Deserialize)]
struct Config {
redis_cluster: deadpool_redis::cluster::Config,
}
impl Config {
pub fn from_env() -> Result<Self, config::ConfigError> {
let mut cfg = config::Config::builder()
.add_source(
config::Environment::default()
.separator("__")
.try_parsing(true)
.list_separator(","),
)
.build()?;
cfg.try_deserialize()
}
}
Fields§
§urls: Option<Vec<String>>
Redis URLs.
connections: Option<Vec<ConnectionInfo>>
redis::ConnectionInfo
structures.
pool: Option<PoolConfig>
Pool configuration.
read_from_replicas: bool
Enables or disables reading from replica nodes in a Redis cluster.
When set to true
, read operations may be distributed across
replica nodes, which can help in load balancing read requests.
When set to false
, all read operations will be directed to the
master node(s). This option is particularly useful in a high-availability
setup where read scalability is needed.
Default is false
.
Implementations§
source§impl Config
impl Config
sourcepub fn create_pool(
&self,
runtime: Option<Runtime>,
) -> Result<Pool, CreatePoolError>
pub fn create_pool( &self, runtime: Option<Runtime>, ) -> Result<Pool, CreatePoolError>
sourcepub fn builder(&self) -> Result<PoolBuilder, ConfigError>
pub fn builder(&self) -> Result<PoolBuilder, ConfigError>
sourcepub fn get_pool_config(&self) -> PoolConfig
pub fn get_pool_config(&self) -> PoolConfig
Returns deadpool::managed::PoolConfig
which can be used to construct
a deadpool::managed::Pool
instance.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
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
Mutably borrows from an owned value. Read more
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)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)