pub struct Config {
pub urls: Option<Vec<String>>,
pub server_type: SentinelServerType,
pub master_name: String,
pub connections: Option<Vec<ConnectionInfo>>,
pub node_connection_info: Option<SentinelNodeConnectionInfo>,
pub pool: Option<PoolConfig>,
}
Expand description
Configuration object.
§Example (from environment)
By enabling the serde
feature you can read the configuration using the
config
crate as following:
REDIS_SENTINEL__URLS=redis://127.0.0.1:26379,redis://127.0.0.1:26380
REDIS_SENTINEL__MASTER_NAME=mymaster
REDIS_SENTINEL__SERVER_TYPE=master
REDIS_SENTINEL__POOL__MAX_SIZE=16
REDIS_SENTINEL__POOL__TIMEOUTS__WAIT__SECS=2
REDIS_SENTINEL__POOL__TIMEOUTS__WAIT__NANOS=0
#[derive(serde::Deserialize)]
struct Config {
redis_sentinel: deadpool_redis::sentinel::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.
server_type: SentinelServerType
ServerType
master_name: String
Sentinel setup master name. default value is mymaster
connections: Option<Vec<ConnectionInfo>>
redis::ConnectionInfo
structures.
node_connection_info: Option<SentinelNodeConnectionInfo>
redis::sentinel::SentinelNodeConnectionInfo
structures.
pool: Option<PoolConfig>
Pool configuration.
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.
Sourcepub fn from_urls<T: Into<Vec<String>>>(
urls: T,
master_name: String,
server_type: SentinelServerType,
) -> Config
pub fn from_urls<T: Into<Vec<String>>>( urls: T, master_name: String, server_type: SentinelServerType, ) -> Config
Creates a new Config
from the given Redis URL (like
redis://127.0.0.1
).
Sourcepub fn with_node_connection_info(
self,
node_connection_info: Option<SentinelNodeConnectionInfo>,
) -> Self
pub fn with_node_connection_info( self, node_connection_info: Option<SentinelNodeConnectionInfo>, ) -> Self
Sets the connection info used to connect to the underlying redis servers (eg: tls mode/db/username/..)
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