diff --git a/src/db/kv/index/hashmap.rs b/src/db/kv/index/hashmap.rs deleted file mode 100644 index 88293864..00000000 --- a/src/db/kv/index/hashmap.rs +++ /dev/null @@ -1,69 +0,0 @@ -use redis::AsyncCommands; - -use crate::{db::connectors::redis::get_redis_conn, types::DynError}; - -/// puts multiple values into a hashmap in Redis -/// -/// # Arguments -/// -/// * `prefix` - A string slice that represents the prefix for the Redis key. -/// * `key` - A string slice that represents the key under which the value is stored. -/// * `values` - A vector of tuples containing the field and value to be stored. -/// -/// # Errors -/// -/// Returns an error if the operation fails. -pub async fn put_index_hashmap( - prefix: &str, - key: &str, - values: &[(&str, &str)], -) -> Result<(), DynError> { - let mut conn = get_redis_conn().await?; - let index_key = format!("{}:{}", prefix, key); - let _: () = conn.hset_multiple(index_key, values).await?; - Ok(()) -} - -/// gets a value from a hashmap in Redis -/// -/// # Arguments -/// -/// * `prefix` - A string slice that represents the prefix for the Redis key. -/// * `key` - A string slice that represents the key under which the value is stored. -/// * `field` - A string slice that represents the field under which the value is stored. -/// -/// # Errors -/// -/// Returns an error if the operation fails. -/// -/// # Returns -/// -/// Returns an Option containing the value if it exists, or None if it does not. -pub async fn get_index_hashmap( - prefix: &str, - key: &str, - field: &str, -) -> Result, DynError> { - let mut conn = get_redis_conn().await?; - let index_key = format!("{}:{}", prefix, key); - let value: Option = conn.hget(index_key, field).await?; - Ok(value) -} - -/// deletes a value from a hashmap in Redis -/// -/// # Arguments -/// -/// * `prefix` - A string slice that represents the prefix for the Redis key. -/// * `key` - A string slice that represents the key under which the value is stored. -/// * `field` - A string slice that represents the field under which the value is stored. -/// -/// # Errors -/// -/// Returns an error if the operation fails. -pub async fn del_index_hashmap(prefix: &str, key: &str, field: &str) -> Result<(), DynError> { - let mut conn = get_redis_conn().await?; - let index_key = format!("{}:{}", prefix, key); - let _: () = conn.hdel(index_key, field).await?; - Ok(()) -} diff --git a/src/db/kv/index/mod.rs b/src/db/kv/index/mod.rs index cb7e6fea..480a2796 100644 --- a/src/db/kv/index/mod.rs +++ b/src/db/kv/index/mod.rs @@ -1,5 +1,4 @@ /// Module for redis Indexing operations split into modules by Redis types -pub mod hashmap; pub mod json; pub mod lists; pub mod sets; diff --git a/src/db/kv/traits.rs b/src/db/kv/traits.rs index 56520fdd..6eda4682 100644 --- a/src/db/kv/traits.rs +++ b/src/db/kv/traits.rs @@ -679,70 +679,4 @@ pub trait RedisOps: Serialize + DeserializeOwned + Send + Sync { let key = key_parts.join(":"); sorted_sets::get_lex_range("Sorted", &key, min, max, skip, limit).await } - - /// Puts multiple values into a hashmap in Redis. - /// - /// # Arguments - /// - /// * `key_parts` - A slice of string slices used to form the key under which the value is stored. - /// * `values` - A vector of tuples containing the field and value to be stored. - /// - /// # Errors - /// - /// Returns an error if the operation fails. - /// - /// # Returns - /// - /// Returns a `Result` indicating success or failure. - async fn put_index_hashmap( - key_parts: &[&str], - values: &[(&str, &str)], - ) -> Result<(), DynError> { - let prefix = Self::prefix().await; - let key = key_parts.join(":"); - hashmap::put_index_hashmap(&prefix, &key, values).await - } - - /// Gets a value from a hashmap in Redis. - /// - /// # Arguments - /// - /// * `key_parts` - A slice of string slices used to form the key under which the value is stored. - /// * `field` - A string slice representing the field to retrieve from the hashmap. - /// - /// # Returns - /// - /// Returns an `Option` containing the value if it exists, or `None` if the field does not exist. - /// - /// # Errors - /// - /// Returns an error if the operation fails. - async fn try_from_index_hashmap( - key_parts: &[&str], - field: &str, - ) -> Result, DynError> { - let prefix = Self::prefix().await; - let key = key_parts.join(":"); - hashmap::get_index_hashmap(&prefix, &key, field).await - } - - /// Deletes a field from a hashmap in Redis. - /// - /// # Arguments - /// - /// * `key_parts` - A slice of string slices used to form the key under which the value is stored. - /// * `field` - A string slice representing the field to delete from the hashmap. - /// - /// # Returns - /// - /// Returns a `Result` indicating success or failure. - /// - /// # Errors - /// - /// Returns an error if the operation fails. - async fn remove_from_index_hashmap(key_parts: &[&str], field: &str) -> Result<(), DynError> { - let prefix = Self::prefix().await; - let key = key_parts.join(":"); - hashmap::del_index_hashmap(&prefix, &key, field).await - } }