mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
40 lines
1.0 KiB
Rust
40 lines
1.0 KiB
Rust
use std::sync::Arc;
|
|
|
|
pub trait KvStorePartition {
|
|
fn partition_number(key: PartitionKey<'_>, num_partitions: u8) -> u32 {
|
|
crc32fast::hash(key.to_string().as_bytes()) % u32::from(num_partitions)
|
|
}
|
|
|
|
fn shard_key(key: PartitionKey<'_>, num_partitions: u8) -> String {
|
|
format!("shard_{}", Self::partition_number(key, num_partitions))
|
|
}
|
|
}
|
|
|
|
#[allow(unused)]
|
|
pub enum PartitionKey<'a> {
|
|
MerchantIdPaymentId {
|
|
merchant_id: &'a str,
|
|
payment_id: &'a str,
|
|
},
|
|
}
|
|
|
|
impl<'a> std::fmt::Display for PartitionKey<'a> {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match *self {
|
|
PartitionKey::MerchantIdPaymentId {
|
|
merchant_id,
|
|
payment_id,
|
|
} => f.write_str(&format!("mid_{merchant_id}_pid_{payment_id}")),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait RedisConnInterface {
|
|
fn get_redis_conn(
|
|
&self,
|
|
) -> error_stack::Result<
|
|
Arc<redis_interface::RedisConnectionPool>,
|
|
redis_interface::errors::RedisError,
|
|
>;
|
|
}
|