Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consolidate fetch & fetchpost code #1671

Merged
merged 8 commits into from
Mar 14, 2024
Next Next commit
fetch: centralize RedisConfig struct in fetch, so we can use it in …
…fetchpost
  • Loading branch information
jqnatividad committed Mar 13, 2024
commit ef6e21390ccdd5153683c76e6127c508370cd350
24 changes: 14 additions & 10 deletions src/cmd/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ struct Args {
static MEM_CACHE_SIZE: OnceLock<usize> = OnceLock::new();

// connect to Redis at localhost, using database 1 by default when --redis is enabled
static QSV_REDIS_CONNSTR_ENV: &str = "QSV_REDIS_CONNSTR";
static QSV_REDIS_MAX_POOL_SIZE_ENV: &str = "QSV_REDIS_MAX_POOL_SIZE";
static QSV_REDIS_TTL_SECS_ENV: &str = "QSV_REDIS_TTL_SECS";
static QSV_REDIS_TTL_REFRESH_ENV: &str = "QSV_REDIS_TTL_REFRESH";
static DEFAULT_REDIS_CONN_STR: &str = "redis:https://127.0.0.1:6379/1";
static DEFAULT_REDIS_TTL_SECS: u64 = 60 * 60 * 24 * 28; // 28 days in seconds
static DEFAULT_REDIS_POOL_SIZE: u32 = 20;
Expand Down Expand Up @@ -334,26 +338,26 @@ enum ReportKind {
}

#[derive(Debug)]
struct RedisConfig {
conn_str: String,
max_pool_size: u32,
ttl_secs: u64,
ttl_refresh: bool,
pub struct RedisConfig {
pub conn_str: String,
pub max_pool_size: u32,
pub ttl_secs: u64,
pub ttl_refresh: bool,
}
impl RedisConfig {
fn new() -> RedisConfig {
pub fn new() -> RedisConfig {
Self {
conn_str: std::env::var("QSV_REDIS_CONNSTR")
conn_str: std::env::var(QSV_REDIS_CONNSTR_ENV)
.unwrap_or_else(|_| DEFAULT_REDIS_CONN_STR.to_string()),
max_pool_size: std::env::var("QSV_REDIS_MAX_POOL_SIZE")
max_pool_size: std::env::var(QSV_REDIS_MAX_POOL_SIZE_ENV)
.unwrap_or_else(|_| DEFAULT_REDIS_POOL_SIZE.to_string())
.parse()
.unwrap_or(DEFAULT_REDIS_POOL_SIZE),
ttl_secs: std::env::var("QSV_REDIS_TTL_SECS")
ttl_secs: std::env::var(QSV_REDIS_TTL_SECS_ENV)
.unwrap_or_else(|_| DEFAULT_REDIS_TTL_SECS.to_string())
.parse()
.unwrap_or(DEFAULT_REDIS_TTL_SECS),
ttl_refresh: util::get_envvar_flag("QSV_REDIS_TTL_REFRESH"),
ttl_refresh: util::get_envvar_flag(QSV_REDIS_TTL_REFRESH_ENV),
}
}
}
Expand Down