mirror of
https://codeberg.org/icewind/nextcloud-config-parser.git
synced 2026-06-03 08:34:13 +02:00
redis 0.21
This commit is contained in:
parent
0bf1ff020a
commit
2d2fa8a31e
3 changed files with 27 additions and 20 deletions
18
src/lib.rs
18
src/lib.rs
|
|
@ -30,35 +30,37 @@ pub enum RedisConfig {
|
|||
impl RedisConfig {
|
||||
pub fn addr(&self) -> impl Iterator<Item = &ConnectionAddr> {
|
||||
let boxed: Box<dyn Iterator<Item = &ConnectionAddr>> = match self {
|
||||
RedisConfig::Single(conn) => Box::new(once(conn.addr.as_ref())),
|
||||
RedisConfig::Cluster(conns) => Box::new(conns.iter().map(|conn| conn.addr.as_ref())),
|
||||
RedisConfig::Single(conn) => Box::new(once(&conn.addr)),
|
||||
RedisConfig::Cluster(conns) => Box::new(conns.iter().map(|conn| &conn.addr)),
|
||||
};
|
||||
boxed
|
||||
}
|
||||
|
||||
pub fn db(&self) -> i64 {
|
||||
match self {
|
||||
RedisConfig::Single(conn) => conn.db,
|
||||
RedisConfig::Cluster(conns) => conns.first().map(|conn| conn.db).unwrap_or_default(),
|
||||
RedisConfig::Single(conn) => conn.redis.db,
|
||||
RedisConfig::Cluster(conns) => {
|
||||
conns.first().map(|conn| conn.redis.db).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn username(&self) -> Option<&str> {
|
||||
match self {
|
||||
RedisConfig::Single(conn) => conn.username.as_deref(),
|
||||
RedisConfig::Single(conn) => conn.redis.username.as_deref(),
|
||||
RedisConfig::Cluster(conns) => conns
|
||||
.first()
|
||||
.map(|conn| conn.username.as_deref())
|
||||
.map(|conn| conn.redis.username.as_deref())
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn passwd(&self) -> Option<&str> {
|
||||
match self {
|
||||
RedisConfig::Single(conn) => conn.passwd.as_deref(),
|
||||
RedisConfig::Single(conn) => conn.redis.password.as_deref(),
|
||||
RedisConfig::Cluster(conns) => conns
|
||||
.first()
|
||||
.map(|conn| conn.passwd.as_deref())
|
||||
.map(|conn| conn.redis.password.as_deref())
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
src/nc.rs
23
src/nc.rs
|
|
@ -298,26 +298,30 @@ fn parse_redis_options(parsed: &Value) -> RedisConfig {
|
|||
};
|
||||
|
||||
let db = redis_options["dbindex"].clone().into_int().unwrap_or(0);
|
||||
let passwd = redis_options["password"]
|
||||
let password = redis_options["password"]
|
||||
.as_str()
|
||||
.filter(|pass| !pass.is_empty())
|
||||
.map(String::from);
|
||||
|
||||
match address {
|
||||
RedisAddress::Single(addr) => RedisConfig::Single(ConnectionInfo {
|
||||
addr: Box::new(addr),
|
||||
db,
|
||||
username: None,
|
||||
passwd,
|
||||
addr,
|
||||
redis: RedisConnectionInfo {
|
||||
db,
|
||||
username: None,
|
||||
password,
|
||||
},
|
||||
}),
|
||||
RedisAddress::Cluster(addresses) => RedisConfig::Cluster(
|
||||
addresses
|
||||
.into_iter()
|
||||
.map(|addr| ConnectionInfo {
|
||||
addr: Box::new(addr),
|
||||
db,
|
||||
username: None,
|
||||
passwd: passwd.clone(),
|
||||
addr,
|
||||
redis: RedisConnectionInfo {
|
||||
db,
|
||||
username: None,
|
||||
password: password.clone(),
|
||||
},
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
|
|
@ -346,6 +350,7 @@ fn assert_debug_equal<T: Debug>(a: T, b: T) {
|
|||
assert_eq!(format!("{:?}", a), format!("{:?}", b),);
|
||||
}
|
||||
|
||||
use redis::RedisConnectionInfo;
|
||||
#[cfg(test)]
|
||||
#[allow(unused_imports)]
|
||||
use sqlx::{any::AnyConnectOptions, postgres::PgConnectOptions};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue