refactor: use generic function to push to drainer (#496)

This commit is contained in:
Kartikeya Hegde
2023-02-06 17:18:28 +05:30
committed by GitHub
parent 9381a37f8f
commit e4b525485e
4 changed files with 67 additions and 108 deletions

View File

@ -45,4 +45,29 @@ impl Store {
// Example: {shard_5}_drainer_stream
format!("{{{}}}_{}", shard_key, self.config.drainer_stream_name,)
}
#[cfg(feature = "kv_store")]
pub(crate) async fn push_to_drainer_stream<T>(
&self,
redis_entry: storage_models::kv::TypedSql,
partition_key: crate::utils::storage_partitioning::PartitionKey<'_>,
) -> crate::core::errors::CustomResult<(), crate::core::errors::StorageError>
where
T: crate::utils::storage_partitioning::KvStorePartition,
{
use error_stack::ResultExt;
let shard_key = T::shard_key(partition_key, self.config.drainer_num_partitions);
let stream_name = self.get_drainer_stream_name(&shard_key);
self.redis_conn
.stream_append_entry(
&stream_name,
&redis_interface::RedisEntryId::AutoGeneratedID,
redis_entry
.to_field_value_pairs()
.change_context(crate::core::errors::StorageError::KVError)?,
)
.await
.change_context(crate::core::errors::StorageError::KVError)
}
}