refactor(storage_impl): Integrate the composite store from external crate (#1921)

This commit is contained in:
Sampras Lopes
2023-08-14 18:46:31 +05:30
committed by GitHub
parent b1e4e3883d
commit 9f199d9ab8
44 changed files with 490 additions and 445 deletions

View File

@ -1,13 +1,15 @@
use common_utils::ext_traits::AsyncExt;
use error_stack::ResultExt;
use redis_interface::errors::RedisError;
use storage_impl::redis::{
cache::{Cache, CacheKind, Cacheable},
pub_sub::PubSubInterface,
};
use super::StorageInterface;
use crate::{
cache::{self, Cacheable},
consts,
core::errors::{self, CustomResult},
services::PubSubInterface,
};
pub async fn get_or_populate_redis<T, F, Fut>(
@ -53,7 +55,7 @@ pub async fn get_or_populate_in_memory<T, F, Fut>(
store: &dyn StorageInterface,
key: &str,
fun: F,
cache: &cache::Cache,
cache: &Cache,
) -> CustomResult<T, errors::StorageError>
where
T: Cacheable + serde::Serialize + serde::de::DeserializeOwned + std::fmt::Debug + Clone,
@ -74,7 +76,7 @@ pub async fn redact_cache<T, F, Fut>(
store: &dyn StorageInterface,
key: &str,
fun: F,
in_memory: Option<&cache::Cache>,
in_memory: Option<&Cache>,
) -> CustomResult<T, errors::StorageError>
where
F: FnOnce() -> Fut + Send,
@ -99,7 +101,7 @@ where
pub async fn publish_into_redact_channel<'a>(
store: &dyn StorageInterface,
key: cache::CacheKind<'a>,
key: CacheKind<'a>,
) -> CustomResult<usize, errors::StorageError> {
let redis_conn = store
.get_redis_conn()
@ -116,7 +118,7 @@ pub async fn publish_into_redact_channel<'a>(
pub async fn publish_and_redact<'a, T, F, Fut>(
store: &dyn StorageInterface,
key: cache::CacheKind<'a>,
key: CacheKind<'a>,
fun: F,
) -> CustomResult<T, errors::StorageError>
where