| Crates.io | redis_config |
| lib.rs | redis_config |
| version | 0.3.0 |
| created_at | 2023-10-05 22:07:38.922129+00 |
| updated_at | 2025-09-21 00:12:42.032795+00 |
| description | Implementation of Redis source as Async source for config-rs crate. |
| homepage | https://github.com/danik-tro/redis-config |
| repository | https://github.com/danik-tro/redis-config |
| max_upload_size | |
| id | 994594 |
| size | 75,510 |
Implementation of Redis source as Async source for config-rs crate.
redis-config extends the list of possible sources provided by config-rs and provides an asynchronous RedisSource source using the redis-rs.
RedisSource supports reading configuration:
There are a few features defined in redis-rs that can enable additional functionality if so desired. Some of them are turned on by default.
tokio-native-tls-comp: enables support for native-tls for tokio (optional)
tokio-rustls-comp: enables support for rustls for tokio (optional).
See the examples for general usage information.
# Cargo.toml
[dependencies]
config = "0.15.6"
redis_config = { version = "*", features = ["tokio-comp"]}
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }
serde = { version = "1.0", features = ["derive"]}
use config::builder::AsyncState;
use redis_config::{states, RedisSource};
// hardcoded values, shouldn't be in production
const REDIS_URL: &str = "redis://127.0.0.1:6379";
const SOURCE_KEY: &str = "application-settings";
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone)]
struct ServerSettings {
ttl: i64,
path: String,
// another settings
// ...
}
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
struct DbSettings {
pool_size: usize,
// another settings
// ...
}
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
struct ApplicationSettings {
// settings that will be taken from RedisSource
server: ServerSettings,
// settings that will be taken from Env
db: DbSettings,
}
async fn get_config() -> Result<ApplicationSettings, config::ConfigError> {
let config = config::ConfigBuilder::<AsyncState>::default()
.add_source(
config::Environment::with_prefix("APP")
.separator("__")
.try_parsing(true),
)
.add_async_source(
RedisSource::<_, states::PlainString>::try_new(SOURCE_KEY, REDIS_URL)
.map_err(|err| config::ConfigError::NotFound(err.to_string()))?,
)
.build()
.await?;
config.try_deserialize()
}
#[tokio::main]
async fn main() {
let config = get_config().await.unwrap();
}
See the documentation for more usage information.
redis_config is primarily distributed under the terms of both the MIT license.
See LICENSE for details.