mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	feat: add timeout for set command on hashes and add function to allow retry in database (#509)
				
					
				
			This commit is contained in:
		| @ -1,3 +1,5 @@ | ||||
| use crate::{core::errors, routes::metrics}; | ||||
|  | ||||
| #[cfg(feature = "kv_store")] | ||||
| /// Generates hscan field pattern. Suppose the field is pa_1234_ref_1211 it will generate | ||||
| /// pa_1234_ref_* | ||||
| @ -8,3 +10,26 @@ pub fn generate_hscan_pattern_for_refund(sk: &str) -> String { | ||||
|         .collect::<Vec<&str>>() | ||||
|         .join("_") | ||||
| } | ||||
|  | ||||
| // The first argument should be a future while the second argument should be a closure that returns a future for a database call | ||||
| pub async fn try_redis_get_else_try_database_get<F, RFut, DFut, T>( | ||||
|     redis_fut: RFut, | ||||
|     database_call_closure: F, | ||||
| ) -> errors::CustomResult<T, errors::StorageError> | ||||
| where | ||||
|     F: FnOnce() -> DFut, | ||||
|     RFut: futures::Future<Output = errors::CustomResult<T, redis_interface::errors::RedisError>>, | ||||
|     DFut: futures::Future<Output = errors::CustomResult<T, errors::StorageError>>, | ||||
| { | ||||
|     let redis_output = redis_fut.await; | ||||
|     match redis_output { | ||||
|         Ok(output) => Ok(output), | ||||
|         Err(redis_error) => match redis_error.current_context() { | ||||
|             redis_interface::errors::RedisError::NotFound => { | ||||
|                 metrics::KV_MISS.add(&metrics::CONTEXT, 1, &[]); | ||||
|                 database_call_closure().await | ||||
|             } | ||||
|             _ => Err(redis_error.change_context(errors::StorageError::KVError)), | ||||
|         }, | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Nishant Joshi
					Nishant Joshi