pub struct RedisConfig {
pub connection_url: Option<String>,
pub host: Option<String>,
pub port: Option<u16>,
pub username: Option<String>,
pub password: Option<String>,
pub db: Option<u64>,
pub connection_timeout: Duration,
pub connection_pool_size: u32,
}Expand description
RedisConfig represents the configuration for connecting to a Redis instance.
This configuration object is used to set up a connection pool to Redis, providing necessary details such as the Redis host, port, authentication credentials, and pool settings.
In more advanced setups, such as Redis clusters or socket connections, the connection_url field
can be used to provide a direct connection string. If connection_url is provided,
fields like host, port, and db become optional.
Configuration fields can be loaded from various sources, such as YAML, JSON configuration files, or from environment variables.
Example configuration in YAML:
host: localhost
port: 6379
username: username
password: top_secret_password
db: 0
connection_timeout:
secs: 60
nanos: 0
connection_pool_size: 10Another example configuration in YAML:
connection_url: "redis://username:password@localhost:6379/0"
connection_timeout:
secs: 60
nanos: 0
connection_pool_size: 10Fields like connection_timeout and connection_pool_size control how the connection pool behaves.
Fields§
§connection_url: Option<String>Optional direct connection URL (useful for Redis clusters or socket connections).
If connection_url is specified, the host, port, and db fields become optional and are not used.
host: Option<String>The Redis server host address (e.g., localhost).
port: Option<u16>The port to connect to the Redis server (e.g., 6379 for Redis).
username: Option<String>The optional username to authenticate with Redis (mostly used in Redis 6+ with ACLs).
password: Option<String>The optional password to authenticate with Redis.
db: Option<u64>The database number to connect to (default is 0).
connection_timeout: DurationThe timeout duration for establishing a connection to the Redis server.
connection_pool_size: u32The maximum number of connections allowed in the pool.
Implementations§
Source§impl RedisConfig
impl RedisConfig
Sourcepub fn check(&self) -> Result<()>
pub fn check(&self) -> Result<()>
Checks the validity of the configuration.
If connection_url is provided, the configuration is considered valid.
Otherwise, host, port, and db must be provided for a valid configuration.
§Returns
Ok(()) if the configuration is valid, or an anyhow::Error explaining the missing fields.
Trait Implementations§
Source§impl Debug for RedisConfig
impl Debug for RedisConfig
Source§impl<'de> Deserialize<'de> for RedisConfig
impl<'de> Deserialize<'de> for RedisConfig
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>,
Auto Trait Implementations§
impl Freeze for RedisConfig
impl RefUnwindSafe for RedisConfig
impl Send for RedisConfig
impl Sync for RedisConfig
impl Unpin for RedisConfig
impl UnwindSafe for RedisConfig
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> 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