use anyhow::Result;
use regex::Regex;
use super::{RedisInfo, TopologyService};
impl TopologyService {
pub fn parse_redis_url(&self, url: &str) -> Result<RedisInfo> {
let url_pattern = Regex::new(r"redis://([^:]+):(\d+)")?;
if let Some(caps) = url_pattern.captures(url) {
let host = caps.get(1).map(|m| m.as_str()).unwrap_or("localhost");
let port = caps.get(2).and_then(|m| m.as_str().parse::<u16>().ok()).unwrap_or(6379);
Ok(RedisInfo {
url: url.to_string(),
host: host.to_string(),
port,
})
} else {
Ok(RedisInfo {
url: url.to_string(),
host: "localhost".to_string(),
port: 6379,
})
}
}
}