mecha10-dev 0.6.5

Mecha10 dev services — node discovery, topology analysis, and dev mode support
Documentation
//! Redis connection and service port extraction

use anyhow::Result;
use regex::Regex;

use super::{RedisInfo, TopologyService};

impl TopologyService {
    /// Parse Redis URL into components
    ///
    /// Note: This method is public primarily for testing purposes.
    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,
            })
        }
    }
}