mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
refactor: use generic function to push to drainer (#496)
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user