Skip to main content

mecha10_dev/services/topology/
ports.rs

1//! Redis connection and service port extraction
2
3use anyhow::Result;
4use regex::Regex;
5
6use super::{RedisInfo, TopologyService};
7
8impl TopologyService {
9    /// Parse Redis URL into components
10    ///
11    /// Note: This method is public primarily for testing purposes.
12    pub fn parse_redis_url(&self, url: &str) -> Result<RedisInfo> {
13        let url_pattern = Regex::new(r"redis://([^:]+):(\d+)")?;
14
15        if let Some(caps) = url_pattern.captures(url) {
16            let host = caps.get(1).map(|m| m.as_str()).unwrap_or("localhost");
17            let port = caps.get(2).and_then(|m| m.as_str().parse::<u16>().ok()).unwrap_or(6379);
18
19            Ok(RedisInfo {
20                url: url.to_string(),
21                host: host.to_string(),
22                port,
23            })
24        } else {
25            Ok(RedisInfo {
26                url: url.to_string(),
27                host: "localhost".to_string(),
28                port: 6379,
29            })
30        }
31    }
32}