From c3afd69a34ab6573c4b780e2013c9e282ffdfacf Mon Sep 17 00:00:00 2001 From: JMTamayo Date: Sat, 25 Jan 2025 15:42:43 -0500 Subject: [PATCH 1/7] Remove unnecessary module connection.rs --- redsumer-rs/src/core/connection.rs | 77 ---------------------------- redsumer-rs/src/core/mod.rs | 1 - redsumer-rs/src/redsumer/consumer.rs | 5 +- redsumer-rs/src/redsumer/producer.rs | 5 +- 4 files changed, 4 insertions(+), 84 deletions(-) delete mode 100644 redsumer-rs/src/core/connection.rs diff --git a/redsumer-rs/src/core/connection.rs b/redsumer-rs/src/core/connection.rs deleted file mode 100644 index 0801568..0000000 --- a/redsumer-rs/src/core/connection.rs +++ /dev/null @@ -1,77 +0,0 @@ -use redis::{Commands, ErrorKind, RedisError, RedisResult}; -use tracing::{debug, error}; - -#[allow(unused_imports)] -use crate::core::result::{RedsumerError, RedsumerResult}; - -fn ping(c: &mut C) -> RedisResult -where - C: Commands, -{ - match c.check_connection() { - true => { - debug!("The connection to the Redis server was verified"); - Ok("PONG".into()) - } - false => { - let e: &str = "The connection to the Redis server could not be verified. Please verify the client configuration or server availability"; - error!(e); - Err(RedisError::from((ErrorKind::ClientError, e))) - } - } -} - -/// A trait to verify the connection to the Redis server. -pub trait VerifyConnection { - /// Verify the connection to the Redis server. - /// - /// # Arguments: - /// - No arguments. - /// - /// # Returns: - /// A [`RedsumerResult`] with a [`String`] equal to `PONG` if the connection was verified successfully. Otherwise, a [`RedsumerError`] is returned. - fn ping(&mut self) -> RedsumerResult; -} - -impl VerifyConnection for C -where - C: Commands, -{ - fn ping(&mut self) -> RedsumerResult { - ping(self) - } -} - -#[cfg(test)] -mod test_connection { - use redis::Client; - use redis_test::MockRedisConnection; - - use super::*; - - #[test] - fn test_ping_ok() { - // Create a mock connection: - let mut conn: MockRedisConnection = MockRedisConnection::new(vec![]); - - // Ping the server: - let ping_result: RedsumerResult = conn.ping(); - - // Verify the connection to the server: - assert!(ping_result.is_ok()); - assert_eq!(ping_result.unwrap(), "PONG".to_string()); - } - - #[test] - fn test_ping_error() { - // Create a client from a fake host: - let mut client: Client = Client::open("redis://fakehost/0").unwrap(); - - // Ping the server: - let ping_result: RedsumerResult = client.ping(); - - // Verify the connection to the server: - assert!(ping_result.is_err()); - assert_eq!(ping_result.unwrap_err().to_string(), "The connection to the Redis server could not be verified. Please verify the client configuration or server availability- ClientError"); - } -} diff --git a/redsumer-rs/src/core/mod.rs b/redsumer-rs/src/core/mod.rs index 7558281..15aae01 100644 --- a/redsumer-rs/src/core/mod.rs +++ b/redsumer-rs/src/core/mod.rs @@ -1,4 +1,3 @@ pub mod client; -pub mod connection; pub mod result; pub mod streams; diff --git a/redsumer-rs/src/redsumer/consumer.rs b/redsumer-rs/src/redsumer/consumer.rs index 0089e70..0a64c85 100644 --- a/redsumer-rs/src/redsumer/consumer.rs +++ b/redsumer-rs/src/redsumer/consumer.rs @@ -1,11 +1,10 @@ -use redis::{streams::StreamId, Client}; +use redis::{streams::StreamId, Client, Commands}; use tracing::{debug, info}; use crate::core::streams::types::{LatestPendingMessageId, NextIdToClaim}; #[allow(unused_imports)] use crate::core::{ client::{ClientArgs, RedisClientBuilder}, - connection::VerifyConnection, result::{RedsumerError, RedsumerResult}, streams::{ consumer::{ConsumerCommands, BEGINNING_OF_TIME_ID}, @@ -437,7 +436,7 @@ impl Consumer { ); let mut client: Client = args.build()?; - client.ping()?; + client.ping::()?; client.verify_if_stream_exists(config.get_stream_name())?; client.create_consumer_group( diff --git a/redsumer-rs/src/redsumer/producer.rs b/redsumer-rs/src/redsumer/producer.rs index 3f04db3..f6e842b 100644 --- a/redsumer-rs/src/redsumer/producer.rs +++ b/redsumer-rs/src/redsumer/producer.rs @@ -1,10 +1,9 @@ -use redis::{Client, ToRedisArgs}; +use redis::{Client, Commands, ToRedisArgs}; use tracing::{debug, info}; #[allow(unused_imports)] use crate::core::{ client::{ClientArgs, ClientCredentials, RedisClientBuilder}, - connection::VerifyConnection, result::{RedsumerError, RedsumerResult}, streams::{producer::ProducerCommands, types::Id}, }; @@ -101,7 +100,7 @@ impl Producer { ); let mut client: Client = args.build()?; - client.ping()?; + client.ping::()?; info!("Producer instance created successfully and it is ready to be used"); From 2fa5bd62d81bb700f9e342d3c594dac8119a6d32 Mon Sep 17 00:00:00 2001 From: JMTamayo Date: Sat, 25 Jan 2025 15:45:40 -0500 Subject: [PATCH 2/7] Update Redis version to be greater than or equal to 0.28.0. Update development dependencies to the latest version. --- redsumer-rs/Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/redsumer-rs/Cargo.toml b/redsumer-rs/Cargo.toml index 29db2c4..8e308b9 100644 --- a/redsumer-rs/Cargo.toml +++ b/redsumer-rs/Cargo.toml @@ -13,11 +13,11 @@ categories = ["database-implementations"] authors = ["Juan Manuel Tamayo "] [dependencies] -redis = { version = ">=0.27.2", features = ["streams"] } +redis = { version = ">=0.28.0", features = ["streams"] } tracing = { version = ">=0.1.40" } [dev-dependencies] -redis-test = { version = "0.6.0" } -tokio = { version = "1.41.1", features = ["full"] } -time = { version = "0.3.36" } -uuid = { version = "1.11.0", features = ["v4"] } +redis-test = { version = "0.8.0" } +tokio = { version = "1.43.0", features = ["full"] } +time = { version = "0.3.37" } +uuid = { version = "1.12.1", features = ["v4"] } From 155e5ab02fbcc05410bf44410f94aef06a6294d2 Mon Sep 17 00:00:00 2001 From: JMTamayo Date: Sat, 25 Jan 2025 16:15:31 -0500 Subject: [PATCH 3/7] Include useful commands in README.md for the development process --- README.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index db30b38..43ada05 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ A lightweight implementation of Redis Streams for Rust, allowing you to manage s - **Produce** new messages in a specific *stream*. - **Consume** messages from specific *stream*, setting config parameters that allow you a flexible implementation. It also provides an option to minimize the possibility of consuming the same message simultaneously by more than one consumers from the same consumer group. -## Basic Usage +## BASIC OPERATION #### Produce a new stream message: @@ -191,7 +191,103 @@ The **redis** module provides utilities from the **redis** crate. You can use th The **Value** enum represents a Redis value. It can be converted to a specific type using the **from_redis_value** function. This function can be imported from the **redis** module. -## Contributing +## DEVELOPMENT +To try **redsumer**, follow these recommendations: + +#### Install required tools: +Install the following tools required for the development process. + +##### [Cargo LLVM cov](https://github.com/taiki-e/cargo-llvm-cov/blob/main/README.md): +```bash + cargo install cargo-llvm-cov +``` + +##### [Cargo Nextest](https://nexte.std): +```bash + cargo install cargo-nextest +``` + +##### [Cargo Deny](https://embarkstudios.github.io/cargo-deny/): +```bash + cargo install cargo-deny +``` + +##### [Taplo Client](https://taplo.tamasfe.dev): +```bash + cargo install taplo-cli +``` + +##### [Yamlfmt](https://github.com/google/yamlfmt/blob/main/README.md): +```bash + go install github.com/google/yamlfmt/cmd/yamlfmt@latest +``` + +#### To format the code: +```bash + cargo fmt --all +``` + +#### To verify the code format: +```bash + cargo fmt --all --check +``` + +#### To verify lints: +```bash + cargo clippy --workspace --all-features +``` + +#### To check the project: +```bash + cargo check --workspace --all-features +``` + +#### To format TOML files: +```bash + taplo fmt +``` + +#### To verify the TOML files format: +```bash + taplo fmt --check --verbose --diff +``` + +#### To check correctness of crate manifest: +```bash + cargo verify-project --verbose +``` + +#### To format yaml files: +```bash + yamlfmt . +``` + +#### To verify the yaml files format: +```bash + yamlfmt --lint . +``` + +#### To generate the documentation: +```bash + cargo doc --workspace --all-features --document-private-items --verbose --open +``` + +#### To run doc tests: +```bash + cargo test --workspace --all-features --doc +``` + +#### To test using llvm-cov: +```bash + cargo llvm-cov nextest --workspace --all-features --show-missing-lines --open +``` + +### Security analysis: +```bash + cargo deny --log-level debug check +``` + +## CONTRIBUTING We welcome contributions to **redsumer**. Here are some ways you can contribute: From 71434ee1141cf245c6e2d47b1c0c035390c27f2f Mon Sep 17 00:00:00 2001 From: JMTamayo Date: Sat, 25 Jan 2025 16:15:58 -0500 Subject: [PATCH 4/7] Update CHANGELOG.md for last changes --- CHANGELOG.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 794b834..4eb8242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## ✨ v0.5.2 [*Pending*] +## ✨ v0.5.3 [*Pending*] + +### Changed: + +- 🚀 Update Redis version to be greater than or equal to 0.28.0. By [@JMTamayo](https://github.com/JMTamayo). +- 🚀 Update development dependencies to the latest version. By [@JMTamayo](https://github.com/JMTamayo). +- 🚀 Include useful commands in README.md for the development process. By [@JMTamayo](https://github.com/JMTamayo). + +### Removed: + +- ❌ Remove unnecessary module connection.rs. By [@JMTamayo](https://github.com/JMTamayo). +- ❌ Remove Makefile. By [@JMTamayo](https://github.com/JMTamayo). + +## ✨ v0.5.2 [2024-12-05] ### Added: From d93eeb2367aa0734457d2dbb328c4f74bfd952e5 Mon Sep 17 00:00:00 2001 From: JMTamayo Date: Sat, 25 Jan 2025 16:26:42 -0500 Subject: [PATCH 5/7] Replace ubuntu-latest for ubuntu-24.04 --- .github/workflows/CI.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4431d8d..dd87220 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -2,9 +2,11 @@ name: CI on: push: - branches: ["main"] + branches: + - "main" pull_request: - branches: ["main"] + branches: + - "main" schedule: - cron: "0 5 * * 0" @@ -15,7 +17,7 @@ env: jobs: Project-Config: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Fetch Repository uses: actions/checkout@v4 @@ -47,7 +49,7 @@ jobs: run: taplo fmt --check --verbose --diff Docs: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 needs: Project-Config steps: - name: Fetch Repository @@ -63,7 +65,7 @@ jobs: run: cargo test --workspace --all-features --doc Build: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 needs: Project-Config steps: - name: Fetch Repository @@ -84,7 +86,7 @@ jobs: run: cargo build --workspace --all-features Tests: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 needs: Build steps: - name: Fetch Repository @@ -99,7 +101,7 @@ jobs: run: cargo llvm-cov nextest --workspace --all-features --show-missing-lines --summary-only --fail-under-lines ${{ env.MIN_LINE_COVERAGE_TARGET }} Security: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 needs: Build steps: - name: Fetch Repository From a04045c09c1b8f1267ddc41acf63bd9d8d55be7b Mon Sep 17 00:00:00 2001 From: JMTamayo Date: Sat, 25 Jan 2025 16:27:24 -0500 Subject: [PATCH 6/7] Update redsumer version from v0.5.2 to v0.5.3 --- redsumer-rs/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redsumer-rs/Cargo.toml b/redsumer-rs/Cargo.toml index 8e308b9..9f8dadc 100644 --- a/redsumer-rs/Cargo.toml +++ b/redsumer-rs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "redsumer" description = "Lightweight implementation of Redis Streams for Rust" -version = "0.5.2" +version = "0.5.3" edition = "2021" license-file = "../LICENSE" readme = "../README.md" From 7c74148b32a02f5d055a9c7bf3f00310e5f9c00a Mon Sep 17 00:00:00 2001 From: JMTamayo Date: Sat, 25 Jan 2025 16:35:39 -0500 Subject: [PATCH 7/7] Make yamlfmt happy --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index dd87220..8f9d735 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -3,10 +3,10 @@ name: CI on: push: branches: - - "main" + - "main" pull_request: branches: - - "main" + - "main" schedule: - cron: "0 5 * * 0"