mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
feat: Add support for a redis pubsub interface (#614)
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
@ -23,3 +23,4 @@ pub(crate) const BASE64_ENGINE_URL_SAFE: base64::engine::GeneralPurpose =
|
||||
base64::engine::general_purpose::URL_SAFE;
|
||||
|
||||
pub(crate) const API_KEY_LENGTH: usize = 64;
|
||||
pub(crate) const PUB_SUB_CHANNEL: &str = "hyperswitch_invalidate";
|
||||
|
||||
@ -44,3 +44,10 @@ macro_rules! newtype {
|
||||
$crate::newtype_impl!($is_pub, $name, $ty_path);
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! async_spawn {
|
||||
($t:block) => {
|
||||
tokio::spawn(async move { $t });
|
||||
};
|
||||
}
|
||||
|
||||
@ -6,13 +6,15 @@ pub mod logger;
|
||||
|
||||
use std::sync::{atomic, Arc};
|
||||
|
||||
use redis_interface::errors::RedisError;
|
||||
use redis_interface::{errors::RedisError, PubSubInterface};
|
||||
|
||||
pub use self::api::*;
|
||||
#[cfg(feature = "basilisk")]
|
||||
pub use self::encryption::*;
|
||||
use crate::{
|
||||
async_spawn,
|
||||
connection::{diesel_make_pg_pool, PgPool},
|
||||
consts,
|
||||
core::errors,
|
||||
};
|
||||
|
||||
@ -38,7 +40,17 @@ impl Store {
|
||||
let redis_conn = Arc::new(crate::connection::redis_connection(config).await);
|
||||
let redis_clone = redis_conn.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let subscriber_conn = redis_conn.clone();
|
||||
|
||||
redis_conn.subscribe(consts::PUB_SUB_CHANNEL).await.ok();
|
||||
|
||||
async_spawn!({
|
||||
if let Err(e) = subscriber_conn.on_message().await {
|
||||
logger::error!(pubsub_err=?e);
|
||||
}
|
||||
});
|
||||
|
||||
async_spawn!({
|
||||
redis_clone.on_error().await;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user