mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
Todo redis interface (#136)
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
//!
|
||||
//! An interface to abstract the `fred` commands
|
||||
//!
|
||||
//! The folder provides generic functions for providing serialization
|
||||
//! and deserialization while calling redis.
|
||||
//! It also includes instruments to provide tracing.
|
||||
//!
|
||||
//!
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
@ -375,8 +379,6 @@ impl super::RedisConnectionPool {
|
||||
|
||||
// Consumer Group API
|
||||
|
||||
//TODO: Handle RedisEntryId Enum cases which are not valid
|
||||
//implement xgroup_create_mkstream if needed
|
||||
#[instrument(level = "DEBUG", skip(self))]
|
||||
pub async fn consumer_group_create(
|
||||
&self,
|
||||
@ -384,6 +386,14 @@ impl super::RedisConnectionPool {
|
||||
group: &str,
|
||||
id: &RedisEntryId,
|
||||
) -> CustomResult<(), errors::RedisError> {
|
||||
if matches!(
|
||||
id,
|
||||
RedisEntryId::AutoGeneratedID | RedisEntryId::UndeliveredEntryID
|
||||
) {
|
||||
// FIXME: Replace with utils::when
|
||||
Err(errors::RedisError::InvalidRedisEntryId)?;
|
||||
}
|
||||
|
||||
self.pool
|
||||
.xgroup_create(stream, group, id, true)
|
||||
.await
|
||||
@ -464,3 +474,30 @@ impl super::RedisConnectionPool {
|
||||
.change_context(errors::RedisError::ConsumerGroupClaimFailed)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use crate::{errors::RedisError, RedisConnectionPool, RedisEntryId, RedisSettings};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_consumer_group_create() {
|
||||
let redis_conn = RedisConnectionPool::new(&RedisSettings::default()).await;
|
||||
|
||||
let result1 = redis_conn
|
||||
.consumer_group_create("TEST1", "GTEST", &RedisEntryId::AutoGeneratedID)
|
||||
.await;
|
||||
let result2 = redis_conn
|
||||
.consumer_group_create("TEST3", "GTEST", &RedisEntryId::UndeliveredEntryID)
|
||||
.await;
|
||||
|
||||
assert!(matches!(
|
||||
result1.unwrap_err().current_context(),
|
||||
RedisError::InvalidRedisEntryId
|
||||
));
|
||||
assert!(matches!(
|
||||
result2.unwrap_err().current_context(),
|
||||
RedisError::InvalidRedisEntryId
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user