use displaydoc::Display;
use serde::{Deserialize, Serialize};
use crate::rubase::BaseEntity;
use crate::rubase::rudto::cfgdto::softdto::SoftDto;
use crate::rubase::rutils::strutils;
#[derive(Debug, Display, Default, Clone, Deserialize, Serialize)]
pub struct RedisDto {
pub addr: String,
pub password: String,
pub db: i32,
pub enable: bool,
}
impl BaseEntity for RedisDto {}
impl RedisDto {
pub fn new(host: String ,password: String, db: i32) -> Self {
Self {
addr: host,
password: password,
db: db,
enable: true,
}
}
pub fn build_url(&self) -> String {
format!("redis://:{}@{}/{}", self.password, self.addr,self.db )
}
pub fn default( ) -> Self {
Self {
addr: "192.168.1.153:26379".to_string(),
password: "223456".to_string(),
db: 0,
enable: true,
}
}
pub fn parse_env_var(&mut self) {
self.addr= strutils::parse_env_var(std::mem::take(&mut self.addr));
self.password= strutils::parse_env_var(std::mem::take(&mut self.password));
}
}