mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
refactor(storage): add redis structs to storage impls (#1910)
This commit is contained in:
28
crates/storage_impl/src/redis/kv_store.rs
Normal file
28
crates/storage_impl/src/redis/kv_store.rs
Normal file
@ -0,0 +1,28 @@
|
||||
pub(crate) 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(crate) 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}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user