Skip to content

Commit

Permalink
fix: semver check added for redis version
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-affinidi committed Dec 20, 2024
1 parent 8ef6f7c commit baffb87
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
13 changes: 7 additions & 6 deletions Cargo.lock

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

3 changes: 2 additions & 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.3'
version = '0.8.4'
edition = "2021"
authors = ["Glenn Gore <[email protected]>"]
description = "Affinidi Messaging"
Expand Down Expand Up @@ -105,3 +105,4 @@ tui-logger = { version = "0.14", features = ["tracing-support"] }
url = "2.5"
uuid = { version = "1.11", features = ["v4", "fast-rng"] }
varint = "0.9"
semver = "1.0.24"
1 change: 1 addition & 0 deletions affinidi-messaging-mediator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tower-http.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
uuid.workspace = true
semver.workspace = true

[dev-dependencies]
console.workspace = true
Expand Down
15 changes: 9 additions & 6 deletions affinidi-messaging-mediator/src/database/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use super::DatabaseHandler;
use crate::common::{config::Config, errors::MediatorError};
use deadpool_redis::Connection;
use redis::aio::PubSub;
use semver::{Version, VersionReq};
use std::{fs::read_to_string, thread::sleep, time::Duration};
use tracing::{error, event, info, Level};

const REDIS_VERSION: &str = "7.2"; // required Redis version
const REDIS_VERSION_REQ: &str = ">=7.2, <8.0";

impl DatabaseHandler {
pub async fn new(config: &Config) -> Result<Self, MediatorError> {
Expand Down Expand Up @@ -156,19 +157,21 @@ async fn _check_server_version(database: &DatabaseHandler) -> Result<String, Med
.next();

if let Some(version) = server_version {
if version.starts_with(REDIS_VERSION) {
let semver_version = Version::parse(&version).unwrap();
let redis_version_req: VersionReq = VersionReq::parse(REDIS_VERSION_REQ).unwrap();
if redis_version_req.matches(&semver_version) {
info!("Redis version is compatible: {}", version);
Ok(version.to_owned())
} else {
error!(
"Redis version ({}) must be equal to major.minor: ({})",
version, REDIS_VERSION
"Redis version ({}) must match ({})",
version, REDIS_VERSION_REQ
);
Err(MediatorError::DatabaseError(
"NA".into(),
format!(
"Redis version ({}) must be equal to major.minor: ({})",
version, REDIS_VERSION
"Redis version ({}) must match ({})",
version, REDIS_VERSION_REQ
),
))
}
Expand Down

0 comments on commit baffb87

Please sign in to comment.