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

feat: redis configuration url #1577

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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