From 9a68e1bf406079d440bd836d6f986abb828ebaa9 Mon Sep 17 00:00:00 2001 From: Renato Dinhani <101204870+dinhani-cw@users.noreply.github.com> Date: Tue, 30 Jul 2024 21:15:56 -0300 Subject: [PATCH] feat: redis configuration url (#1577) --- src/eth/storage/permanent_storage.rs | 10 ++++++++-- src/eth/storage/redis/redis_permanent.rs | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/eth/storage/permanent_storage.rs b/src/eth/storage/permanent_storage.rs index ca1d74425..63b17a673 100644 --- a/src/eth/storage/permanent_storage.rs +++ b/src/eth/storage/permanent_storage.rs @@ -19,6 +19,7 @@ use crate::eth::storage::redis::RedisPermanentStorage; use crate::eth::storage::InMemoryPermanentStorage; use crate::eth::storage::RocksPermanentStorage; use crate::eth::storage::StoragePointInTime; +use crate::log_and_err; /// Permanent (committed) storage operations. pub trait PermanentStorage: Send + Sync + 'static { @@ -84,7 +85,7 @@ pub struct PermanentStorageConfig { pub perm_storage_kind: PermanentStorageKind, /// Storage connection URL. - #[arg(long = "perm-storage-url", env = "PERM_STORAGE_URL")] + #[arg(long = "perm-storage-url", env = "PERM_STORAGE_URL", required_if_eq_any([("perm_storage_kind", "redis")]))] pub perm_storage_url: Option, /// RocksDB storage path prefix to execute multiple local Stratus instances. @@ -112,7 +113,12 @@ impl PermanentStorageConfig { let perm: Box = match self.perm_storage_kind { PermanentStorageKind::InMemory => Box::::default(), - PermanentStorageKind::Redis => Box::new(RedisPermanentStorage::new()?), + PermanentStorageKind::Redis => { + let Some(url) = self.perm_storage_url.as_deref() else { + return log_and_err!("redis connection url not provided when it was expected to be present"); + }; + Box::new(RedisPermanentStorage::new(url)?) + } PermanentStorageKind::Rocks => { let prefix = self.rocks_path_prefix.clone(); diff --git a/src/eth/storage/redis/redis_permanent.rs b/src/eth/storage/redis/redis_permanent.rs index 99edc0893..b5c7adcad 100644 --- a/src/eth/storage/redis/redis_permanent.rs +++ b/src/eth/storage/redis/redis_permanent.rs @@ -33,8 +33,11 @@ pub struct RedisPermanentStorage { } impl RedisPermanentStorage { - pub fn new() -> anyhow::Result { - let client = RedisClient::open("redis://127.0.0.1/")?; + pub fn new(url: &str) -> anyhow::Result { + let client = match RedisClient::open(url) { + Ok(client) => client, + Err(e) => return log_and_err!(reason = e, "failed to create redis client"), + }; Ok(Self { client }) }