Skip to content

Commit

Permalink
feat: redis configuration url (#1577)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored Jul 31, 2024
1 parent 42580c0 commit 9a68e1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/eth/storage/permanent_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String>,

/// RocksDB storage path prefix to execute multiple local Stratus instances.
Expand Down Expand Up @@ -112,7 +113,12 @@ impl PermanentStorageConfig {
let perm: Box<dyn PermanentStorage> = match self.perm_storage_kind {
PermanentStorageKind::InMemory => Box::<InMemoryPermanentStorage>::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();
Expand Down
7 changes: 5 additions & 2 deletions src/eth/storage/redis/redis_permanent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ pub struct RedisPermanentStorage {
}

impl RedisPermanentStorage {
pub fn new() -> anyhow::Result<Self> {
let client = RedisClient::open("redis://127.0.0.1/")?;
pub fn new(url: &str) -> anyhow::Result<Self> {
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 })
}

Expand Down

0 comments on commit 9a68e1b

Please sign in to comment.