mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(drainer): added drainer which reads from redis stream and executes queries on DB (#142)
This commit is contained in:
@ -17,7 +17,7 @@ use fred::{
|
||||
interfaces::{HashesInterface, KeysInterface, StreamsInterface},
|
||||
types::{
|
||||
Expiration, FromRedis, MultipleIDs, MultipleKeys, MultipleOrderedPairs, MultipleStrings,
|
||||
RedisMap, RedisValue, SetOptions, XReadResponse,
|
||||
RedisKey, RedisMap, RedisValue, SetOptions, XCap, XReadResponse,
|
||||
},
|
||||
};
|
||||
use router_env::{tracing, tracing::instrument};
|
||||
@ -313,6 +313,23 @@ impl super::RedisConnectionPool {
|
||||
.change_context(errors::RedisError::StreamDeleteFailed)
|
||||
}
|
||||
|
||||
#[instrument(level = "DEBUG", skip(self))]
|
||||
pub async fn stream_trim_entries<C>(
|
||||
&self,
|
||||
stream: &str,
|
||||
xcap: C,
|
||||
) -> CustomResult<usize, errors::RedisError>
|
||||
where
|
||||
C: TryInto<XCap> + Debug,
|
||||
C::Error: Into<fred::error::RedisError>,
|
||||
{
|
||||
self.pool
|
||||
.xtrim(stream, xcap)
|
||||
.await
|
||||
.into_report()
|
||||
.change_context(errors::RedisError::StreamTrimFailed)
|
||||
}
|
||||
|
||||
#[instrument(level = "DEBUG", skip(self))]
|
||||
pub async fn stream_acknowledge_entries<Ids>(
|
||||
&self,
|
||||
@ -330,19 +347,32 @@ impl super::RedisConnectionPool {
|
||||
.change_context(errors::RedisError::StreamAcknowledgeFailed)
|
||||
}
|
||||
|
||||
#[instrument(level = "DEBUG", skip(self))]
|
||||
pub async fn stream_get_length<K>(&self, stream: K) -> CustomResult<usize, errors::RedisError>
|
||||
where
|
||||
K: Into<RedisKey> + Debug,
|
||||
{
|
||||
self.pool
|
||||
.xlen(stream)
|
||||
.await
|
||||
.into_report()
|
||||
.change_context(errors::RedisError::GetLengthFailed)
|
||||
}
|
||||
|
||||
#[instrument(level = "DEBUG", skip(self))]
|
||||
pub async fn stream_read_entries<K, Ids>(
|
||||
&self,
|
||||
streams: K,
|
||||
ids: Ids,
|
||||
read_count: Option<u64>,
|
||||
) -> CustomResult<XReadResponse<String, String, String, String>, errors::RedisError>
|
||||
where
|
||||
K: Into<MultipleKeys> + Debug,
|
||||
Ids: Into<MultipleIDs> + Debug,
|
||||
{
|
||||
self.pool
|
||||
.xread(
|
||||
Some(self.config.default_stream_read_count),
|
||||
.xread_map(
|
||||
Some(read_count.unwrap_or(self.config.default_stream_read_count)),
|
||||
None,
|
||||
streams,
|
||||
ids,
|
||||
|
||||
@ -18,8 +18,12 @@ pub enum RedisError {
|
||||
StreamAppendFailed,
|
||||
#[error("Failed to read entries from Redis stream")]
|
||||
StreamReadFailed,
|
||||
#[error("Failed to get stream length")]
|
||||
GetLengthFailed,
|
||||
#[error("Failed to delete entries from Redis stream")]
|
||||
StreamDeleteFailed,
|
||||
#[error("Failed to trim entries from Redis stream")]
|
||||
StreamTrimFailed,
|
||||
#[error("Failed to acknowledge Redis stream entry")]
|
||||
StreamAcknowledgeFailed,
|
||||
#[error("Failed to create Redis consumer group")]
|
||||
|
||||
Reference in New Issue
Block a user