Skip to content

Commit

Permalink
fix: semver check added for redis version (#75)
Browse files Browse the repository at this point in the history
* fix: semver check added for redis version

* fix: redis req relaxed

* fix: redis check improved

* fix: redis check fail moved up
  • Loading branch information
robert-affinidi authored Dec 20, 2024
1 parent 8ef6f7c commit 435ae63
Show file tree
Hide file tree
Showing 4 changed files with 32 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
28 changes: 22 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.1, <8.0";

impl DatabaseHandler {
pub async fn new(config: &Config) -> Result<Self, MediatorError> {
Expand Down Expand Up @@ -124,6 +125,11 @@ impl DatabaseHandler {

/// Helper function to check the version of the Redis Server
async fn _check_server_version(database: &DatabaseHandler) -> Result<String, MediatorError> {
let redis_version_req: VersionReq = match VersionReq::parse(REDIS_VERSION_REQ) {
Ok(result) => result,
Err(err) => panic!("Couldn't process required Redis version. Reason: {}", err),
};

let mut conn = database.get_async_connection().await?;
let server_info: String = match deadpool_redis::redis::cmd("INFO")
.arg("SERVER")
Expand Down Expand Up @@ -156,19 +162,29 @@ 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 = match Version::parse(&version) {
Ok(result) => result,
Err(err) => {
error!("Cannot parse Redis version ({}). Reason: {}", version, err);
return Err(MediatorError::DatabaseError(
"NA".into(),
format!("Cannot parse Redis version ({}). Reason: {}", version, err),
));
}
};
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 435ae63

Please sign in to comment.