Skip to content

Commit

Permalink
implements #17
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiss committed May 3, 2024
1 parent 9fd9317 commit 1b820d3
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion examples/2services.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dtypes::redis::DString as String;
use dtypes::redis::types::DString as String;
use std::thread;
use std::thread::sleep;

Expand Down
2 changes: 1 addition & 1 deletion src/redis/bool_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! # Boolean Type
//! This module contains the boolean type.
pub type TBool = crate::redis::Generic<bool>;
pub type TBool = crate::redis::types::Generic<bool>;

#[cfg(test)]
mod tests {
Expand Down
18 changes: 9 additions & 9 deletions src/redis/clock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::redis::Generic;
use crate::redis::types::Generic;
use serde_json::from_str;
use std::ops::{Deref, DerefMut};
use thiserror::Error;
Expand Down Expand Up @@ -75,8 +75,8 @@ where
///
/// # Example
/// ```
/// use dtypes::redis::Generic;
/// use dtypes::redis::ClockOrdered;
/// use dtypes::redis::types::Generic;
/// use dtypes::redis::sync::ClockOrdered;
///
/// let client = redis::Client::open("redis://localhost:6379").unwrap();
/// let mut i32 = Generic::with_value(1, "test_add_clock_ordered_example1", client.clone());
Expand All @@ -91,8 +91,8 @@ where
/// # Example
/// ```
/// use std::thread;
/// use dtypes::redis::Generic;
/// use dtypes::redis::ClockOrdered;
/// use dtypes::redis::types::Generic;
/// use dtypes::redis::sync::ClockOrdered;
///
/// let client = redis::Client::open("redis://localhost:6379").unwrap();
/// let client2 = client.clone();
Expand Down Expand Up @@ -131,8 +131,8 @@ where
/// # Example
/// ```
/// use std::thread;
/// use dtypes::redis::Generic;
/// use dtypes::redis::ClockOrdered;
/// use dtypes::redis::types::Generic;
/// use dtypes::redis::sync::ClockOrdered;
///
/// let client = redis::Client::open("redis://localhost:6379").unwrap();
/// let client2 = client.clone();
Expand Down Expand Up @@ -223,8 +223,8 @@ impl<T> DerefMut for ClockOrdered<T> {
mod tests {
#[test]
fn test_set_load() {
use crate::redis::ClockOrdered;
use crate::redis::Generic;
use crate::redis::sync::ClockOrdered;
use crate::redis::types::Generic;

let client = redis::Client::open("redis://localhost:6379").unwrap();
let i32: Generic<i32> = Generic::new("test_add_clock_ordered", client.clone());
Expand Down
2 changes: 1 addition & 1 deletion src/redis/helper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::redis::Generic;
use crate::redis::types::Generic;
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::fmt::Display;
Expand Down
2 changes: 1 addition & 1 deletion src/redis/integer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The integer module contains the Ti32 struct which is a wrapper around an i32 value stored in Redis.

use crate::redis::Generic;
use crate::redis::types::Generic;
pub type Tusize = Generic<usize>;
pub type Tu8 = Generic<u8>;
pub type Tu16 = Generic<u16>;
Expand Down
5 changes: 2 additions & 3 deletions src/redis/list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::redis::Generic;
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::collections::VecDeque;
Expand All @@ -8,7 +7,7 @@ use std::ops::{Deref, DerefMut};
///
/// # Example
/// ```
/// use dtypes::redis::List;
/// use dtypes::redis::types::List;
///
/// let client = redis::Client::open("redis://localhost:6379").unwrap();
/// let mut list = List::new("test_list", client);
Expand Down Expand Up @@ -157,7 +156,7 @@ where
///
/// # Example
/// ```
/// use dtypes::redis::{ListCache, Mutex};
/// use dtypes::redis::{types::ListCache, sync::Mutex};
///
/// let client = redis::Client::open("redis://localhost:6379").unwrap();
/// let mut list = ListCache::new("test_list2", client);
Expand Down
32 changes: 19 additions & 13 deletions src/redis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//! # Usage
//!
//! ```
//! use dtypes::redis::Di32 as i32;
//! use dtypes::redis::types::Di32 as i32;
//!
//! let client = redis::Client::open("redis://localhost:6379").unwrap();
//! let mut i32 = i32::with_value(1, "test_add", client.clone());
Expand Down Expand Up @@ -54,15 +54,21 @@ mod string;

pub(crate) use helper::apply_operator;

pub use barrier::{Barrier, BarrierWaitResult};
pub use bool_type::TBool as Dbool;
pub use clock::ClockOrdered;
pub use generic::Generic;
pub use integer::{
Ti16 as Di16, Ti32 as Di32, Ti64 as Di64, Ti8 as Di8, Tisize as Disize, Tu16 as Du16,
Tu32 as Du32, Tu64 as Du64, Tu8 as Du8, Tusize as Dusize,
};
pub use list::{List, ListCache, ListIter};
pub use mutex::{Guard, LockError, Mutex};
pub use rwlock::RwLock;
pub use string::TString as DString;
pub mod sync {
pub use crate::redis::barrier::{Barrier, BarrierWaitResult};
pub use crate::redis::clock::ClockOrdered;
pub use crate::redis::mutex::{Guard, LockError, Mutex};
pub use crate::redis::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard};
}

/// Holds all the types that can be stored in Redis.
pub mod types {
pub use crate::redis::bool_type::TBool as Dbool;
pub use crate::redis::generic::Generic;
pub use crate::redis::integer::{
Ti16 as Di16, Ti32 as Di32, Ti64 as Di64, Ti8 as Di8, Tisize as Disize, Tu16 as Du16,
Tu32 as Du32, Tu64 as Du64, Tu8 as Du8, Tusize as Dusize,
};
pub use crate::redis::list::{List, ListCache, ListIter};
pub use crate::redis::string::TString as DString;
}
12 changes: 6 additions & 6 deletions src/redis/mutex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::redis::Generic;
use crate::redis::types::Generic;
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::ops::{Deref, DerefMut};
Expand Down Expand Up @@ -153,8 +153,8 @@ where
///
/// # Example
/// ```
/// use dtypes::redis::Di32 as i32;
/// use dtypes::redis::Mutex;
/// use dtypes::redis::types::Di32 as i32;
/// use dtypes::redis::sync::Mutex;
/// use std::thread::scope;
///
/// let client = redis::Client::open("redis://localhost:6379").unwrap();
Expand Down Expand Up @@ -188,8 +188,8 @@ where
/// # Example
/// ```
/// use std::thread::sleep;
/// use dtypes::redis::Di32 as i32;
/// use dtypes::redis::Mutex;
/// use dtypes::redis::types::Di32 as i32;
/// use dtypes::redis::sync::Mutex;
///
/// let client = redis::Client::open("redis://localhost:6379").unwrap();
/// let mut i32 = i32::new("test_add_example2", client.clone());
Expand Down Expand Up @@ -368,7 +368,7 @@ impl<T> Drop for Guard<'_, T> {
#[cfg(test)]
mod tests {
use super::Mutex;
use crate::redis::Di32;
use crate::redis::types::Di32;
use std::thread;
#[test]
fn test_create_lock() {
Expand Down
12 changes: 6 additions & 6 deletions src/redis/rwlock/lock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::RwLockReadGuard;
use super::RwLockWriteGuard;
use crate::redis::rwlock::constants::{READER_LOCK, UUID_SCRIPT, WRITER_LOCK};
use crate::redis::{Generic, LockError};
use crate::redis::{sync::LockError, types::Generic};
use redis::Connection;
use serde::de::DeserializeOwned;
use serde::Serialize;
Expand All @@ -21,8 +21,8 @@ use std::ops::{Deref, DerefMut};
///
/// ## Linear usage
/// ```
/// use dtypes::redis::RwLock;
/// use dtypes::redis::Di32;
/// use dtypes::redis::sync::RwLock;
/// use dtypes::redis::types::Di32;
/// use std::thread;
///
/// let client = redis::Client::open("redis://localhost:6379").unwrap();
Expand Down Expand Up @@ -54,8 +54,8 @@ use std::ops::{Deref, DerefMut};
/// ```
/// ## Threaded usage
/// ```
/// use dtypes::redis::RwLock;
/// use dtypes::redis::Di32;
/// use dtypes::redis::sync::RwLock;
/// use dtypes::redis::types::Di32;
/// use std::thread;
///
/// let client = redis::Client::open("redis://localhost:6379").unwrap();
Expand Down Expand Up @@ -148,7 +148,7 @@ impl<T> DerefMut for RwLock<T> {
#[cfg(test)]
mod tests {
use super::*;
use crate::redis::*;
use crate::redis::types::*;
use std::mem::ManuallyDrop;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/redis/rwlock/reader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::lock::RwLock;
use crate::redis::rwlock::constants::{LOAD_SCRIPT, READER_LOCK_DROP};
use crate::redis::Generic;
use crate::redis::types::Generic;
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::ops::Deref;
Expand Down
2 changes: 1 addition & 1 deletion src/redis/rwlock/writer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::redis::rwlock::constants::{LOAD_SCRIPT, STORE_SCRIPT, WRITER_LOCK_DROP};
use crate::redis::rwlock::RwLockError;
use crate::redis::{Generic, RwLock};
use crate::redis::{sync::RwLock, types::Generic};
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::ops::{Deref, DerefMut};
Expand Down
2 changes: 1 addition & 1 deletion src/redis/string.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! # String Type
//! This module contains the string type.
use crate::redis::Generic;
use crate::redis::types::Generic;
use std::ops::{Add, AddAssign};

pub type TString = Generic<String>;
Expand Down

0 comments on commit 1b820d3

Please sign in to comment.