feat: add unique constraint restriction for KV (#3723)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Kartikeya Hegde
2024-02-26 13:37:05 +00:00
committed by GitHub
parent 9aabb14a60
commit c117f8ec63
6 changed files with 126 additions and 10 deletions

View File

@ -15,11 +15,11 @@ use common_utils::{
};
use error_stack::{IntoReport, ResultExt};
use fred::{
interfaces::{HashesInterface, KeysInterface, StreamsInterface},
interfaces::{HashesInterface, KeysInterface, SetsInterface, StreamsInterface},
prelude::RedisErrorKind,
types::{
Expiration, FromRedis, MultipleIDs, MultipleKeys, MultipleOrderedPairs, MultipleStrings,
RedisKey, RedisMap, RedisValue, Scanner, SetOptions, XCap, XReadResponse,
MultipleValues, RedisKey, RedisMap, RedisValue, Scanner, SetOptions, XCap, XReadResponse,
},
};
use futures::StreamExt;
@ -27,7 +27,7 @@ use router_env::{instrument, logger, tracing};
use crate::{
errors,
types::{DelReply, HsetnxReply, MsetnxReply, RedisEntryId, SetnxReply},
types::{DelReply, HsetnxReply, MsetnxReply, RedisEntryId, SaddReply, SetnxReply},
};
impl super::RedisConnectionPool {
@ -466,6 +466,23 @@ impl super::RedisConnectionPool {
.change_context(errors::RedisError::JsonDeserializationFailed)
}
#[instrument(level = "DEBUG", skip(self))]
pub async fn sadd<V>(
&self,
key: &str,
members: V,
) -> CustomResult<SaddReply, errors::RedisError>
where
V: TryInto<MultipleValues> + Debug + Send,
V::Error: Into<fred::error::RedisError> + Send,
{
self.pool
.sadd(key, members)
.await
.into_report()
.change_context(errors::RedisError::SetAddMembersFailed)
}
#[instrument(level = "DEBUG", skip(self))]
pub async fn stream_append_entry<F>(
&self,