Skip to content

Commit

Permalink
Support redis password.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloud10240 committed Nov 22, 2023
1 parent b61a41e commit 81620d1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ mod rpc_cache_handler;
lazy_static! {
static ref REDIS: redis::Client = {
let redis_host = env::var("REDIS_HOST").unwrap_or_else(|_| "localhost".to_string());
let redis_url = format!("redis://{}", redis_host);
let redis_password = env::var("REDIS_PASSWORD").unwrap_or_else(|_| "".to_string());

let redis_url = if redis_password.is_empty() {
format!("redis://{}", redis_host)
} else {
format!("redis://:{}@{}", redis_password, redis_host)
};

redis::Client::open(redis_url).expect("Failed to create Redis client")
};
}
Expand Down

0 comments on commit 81620d1

Please sign in to comment.