Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: required redis version lowered to 7.1 #70

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
resolver = "2"

[workspace.package]
version = '0.8.1'
version = '0.8.2'
edition = "2021"
authors = ["Glenn Gore <[email protected]>"]
description = "Affinidi Messaging"
Expand Down
2 changes: 1 addition & 1 deletion affinidi-messaging-mediator/src/database/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use redis::aio::PubSub;
use std::{fs::read_to_string, thread::sleep, time::Duration};
use tracing::{error, event, info, Level};

const REDIS_VERSION: &str = "7.4"; // Minimum Redis version required
const REDIS_VERSION: &str = "7.1"; // Minimum Redis version required

impl DatabaseHandler {
pub async fn new(config: &Config) -> Result<Self, MediatorError> {
Expand Down
48 changes: 33 additions & 15 deletions affinidi-messaging-mediator/src/database/oob_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use sha256::digest;
use std::time::SystemTime;
use tracing::{debug, error, info, span, Instrument, Level};

const HASH_KEY: &str = "OOB_INVITES";
// const HASH_KEY: &str = "OOB_INVITES";
const HASH_KEY_PREFIX: &str = "OOB_INVITES";

impl DatabaseHandler {
/// Stores an OOB Discovery Invitation
Expand Down Expand Up @@ -76,19 +77,26 @@ impl DatabaseHandler {
};

let invite_hash = digest(&base64_invite);
let key = DatabaseHandler::to_cache_key(invite_hash.to_owned());

match deadpool_redis::redis::pipe()
.atomic()
.cmd("HSET")
.arg(HASH_KEY)
.arg(&invite_hash)
// .cmd("HSET")
// .arg(HASH_KEY)
// .arg(&invite_hash)
// .arg(&base64_invite)
// .cmd("HEXPIREAT")
// .arg(HASH_KEY)
// .arg(expire_at)
// .arg("FIELDS")
// .arg(1)
// .arg(&invite_hash)
.cmd("SET")
.arg(key.to_owned())
.arg(&base64_invite)
.cmd("HEXPIREAT")
.arg(HASH_KEY)
.cmd("EXPIREAT")
.arg(key)
.arg(expire_at)
.arg("FIELDS")
.arg(1)
.arg(&invite_hash)
.cmd("HINCRBY")
.arg("GLOBAL")
.arg("OOB_INVITES_CREATED")
Expand Down Expand Up @@ -120,11 +128,14 @@ impl DatabaseHandler {
async move {
let mut conn = self.get_async_connection().await?;

let key = DatabaseHandler::to_cache_key(oob_id.to_owned());
let invitation: Option<String> = match deadpool_redis::redis::pipe()
.atomic()
.cmd("HGET")
.arg(HASH_KEY)
.arg(oob_id)
// .cmd("HGET")
// .arg(HASH_KEY)
// .arg(oob_id)
.cmd("GET")
.arg(key)
.cmd("HINCRBY")
.arg("GLOBAL")
.arg("OOB_INVITES_CLAIMED")
Expand Down Expand Up @@ -157,9 +168,12 @@ impl DatabaseHandler {
async move {
let mut conn = self.get_async_connection().await?;

let result: bool = match deadpool_redis::redis::cmd("HDEL")
.arg(HASH_KEY)
.arg(oob_id)
let key = DatabaseHandler::to_cache_key(oob_id.to_owned());
// let result: bool = match deadpool_redis::redis::cmd("HDEL")
// .arg(HASH_KEY)
// .arg(oob_id)
let result: bool = match deadpool_redis::redis::cmd("DEL")
.arg(key)
.query_async::<bool>(&mut conn)
.await
{
Expand All @@ -180,4 +194,8 @@ impl DatabaseHandler {
.instrument(_span)
.await
}

fn to_cache_key(id: String) -> String {
return format!("{HASH_KEY_PREFIX}{id}");
}
}
Loading