use super::*;
use super::{default_connection_timeout, default_redis_max_connections};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct StorageConfig {
pub database: DatabaseConfig,
pub redis: RedisConfig,
}
#[allow(dead_code)]
impl StorageConfig {
pub fn merge(mut self, other: Self) -> Self {
self.database = self.database.merge(other.database);
self.redis = self.redis.merge(other.redis);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatabaseConfig {
pub url: String,
#[serde(default = "default_max_connections")]
pub max_connections: u32,
#[serde(default = "default_connection_timeout")]
pub connection_timeout: u64,
#[serde(default)]
pub ssl: bool,
#[serde(default)]
pub enabled: bool,
}
impl Default for DatabaseConfig {
fn default() -> Self {
Self {
url: "postgresql://localhost/litellm".to_string(),
max_connections: default_max_connections(),
connection_timeout: default_connection_timeout(),
ssl: false,
enabled: false,
}
}
}
#[allow(dead_code)]
impl DatabaseConfig {
pub fn merge(mut self, other: Self) -> Self {
if !other.url.is_empty() && other.url != "postgresql://localhost/litellm" {
self.url = other.url;
}
if other.max_connections != default_max_connections() {
self.max_connections = other.max_connections;
}
if other.connection_timeout != default_connection_timeout() {
self.connection_timeout = other.connection_timeout;
}
if other.ssl {
self.ssl = other.ssl;
}
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RedisConfig {
pub url: String,
#[serde(default = "default_redis_enabled")]
pub enabled: bool,
#[serde(default = "default_redis_max_connections")]
pub max_connections: u32,
#[serde(default = "default_connection_timeout")]
pub connection_timeout: u64,
#[serde(default)]
pub cluster: bool,
}
impl Default for RedisConfig {
fn default() -> Self {
Self {
url: "redis://localhost:6379".to_string(),
enabled: default_redis_enabled(),
max_connections: default_redis_max_connections(),
connection_timeout: default_connection_timeout(),
cluster: false,
}
}
}
#[allow(dead_code)]
impl RedisConfig {
pub fn merge(mut self, other: Self) -> Self {
if !other.url.is_empty() && other.url != "redis://localhost:6379" {
self.url = other.url;
}
if other.max_connections != default_redis_max_connections() {
self.max_connections = other.max_connections;
}
if other.connection_timeout != default_connection_timeout() {
self.connection_timeout = other.connection_timeout;
}
if other.cluster {
self.cluster = other.cluster;
}
self
}
}
fn default_redis_enabled() -> bool {
true
}