pub type bool = RedisGeneric<bool>;Aliased Type§
struct bool { /* private fields */ }Implementations§
source§impl<T> RedisGeneric<T>where
T: Display + Serialize + DeserializeOwned,
impl<T> RedisGeneric<T>where T: Display + Serialize + DeserializeOwned,
sourcepub fn new(field_name: &str, client: Client) -> RedisGeneric<T>
pub fn new(field_name: &str, client: Client) -> RedisGeneric<T>
The new method creates a new instance of the type. It does not load or store any value in Redis. It only creates the instance.
Example
use types::i32;
let client = redis::Client::open("redis://localhost:6379").unwrap();
let mut i32 = i32::new("test_add", client.clone());
i32.store(1);
let i32 = i32 + i32::with_value(2, "test_add2", client);
assert_eq!(i32, 3);sourcepub fn with_value(value: T, field_name: &str, client: Client) -> RedisGeneric<T>
pub fn with_value(value: T, field_name: &str, client: Client) -> RedisGeneric<T>
The with_value method creates a new instance of the type. If a value is already stored in Redis, it will be overwritten.
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
thread::scope(|s| {
let client = redis::Client::open("redis://localhost:6379").unwrap();
let client2 = client.clone();
let t1 = s.spawn(move || {
let mut string = String::with_value("Hello".to_string(), "test", client);
println!("Thread1: {}", string.cached().unwrap());
assert_eq!(string, "Hello");
sleep(std::time::Duration::from_secs(1));
string.store("World".to_string());
println!("Thread1: {}", string.cached().unwrap());
assert_eq!(string, "World");
});
let t2 = s.spawn(move || {
sleep(std::time::Duration::from_micros(100));
let mut string = String::with_load("test", client2);
println!("Thread2: {}", string.cached().unwrap());
assert_eq!(string, "Hello");
sleep(std::time::Duration::from_secs(2));
string.acquire();
println!("Thread2: {}", string.cached().unwrap());
assert_eq!(string, "World");
});
t1.join().expect("Failed to join thread1");
t2.join().expect("Failed to join thread2");
});
}sourcepub fn with_load(field_name: &str, client: Client) -> RedisGeneric<T>
pub fn with_load(field_name: &str, client: Client) -> RedisGeneric<T>
The with_value_load method creates a new instance of the type. It loads the value from Redis. If there is no value stored in Redis, it stores a None in cache.
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
thread::scope(|s| {
let client = redis::Client::open("redis://localhost:6379").unwrap();
let client2 = client.clone();
let t1 = s.spawn(move || {
let mut string = String::with_value("Hello".to_string(), "test", client);
println!("Thread1: {}", string.cached().unwrap());
assert_eq!(string, "Hello");
sleep(std::time::Duration::from_secs(1));
string.store("World".to_string());
println!("Thread1: {}", string.cached().unwrap());
assert_eq!(string, "World");
});
let t2 = s.spawn(move || {
sleep(std::time::Duration::from_micros(100));
let mut string = String::with_load("test", client2);
println!("Thread2: {}", string.cached().unwrap());
assert_eq!(string, "Hello");
sleep(std::time::Duration::from_secs(2));
string.acquire();
println!("Thread2: {}", string.cached().unwrap());
assert_eq!(string, "World");
});
t1.join().expect("Failed to join thread1");
t2.join().expect("Failed to join thread2");
});
}sourcepub fn with_value_default(
value: T,
field_name: &str,
client: Client
) -> RedisGeneric<T>
pub fn with_value_default( value: T, field_name: &str, client: Client ) -> RedisGeneric<T>
The with_value_default method creates a new instance of the type. If the value is not already stored in Redis, it will be stored. If the value is already stored in Redis, it will be loaded and your given value will be ignored.
sourcepub fn store(&mut self, value: T)
pub fn store(&mut self, value: T)
The set method sets the value of the type.
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
thread::scope(|s| {
let client = redis::Client::open("redis://localhost:6379").unwrap();
let client2 = client.clone();
let t1 = s.spawn(move || {
let mut string = String::with_value("Hello".to_string(), "test", client);
println!("Thread1: {}", string.cached().unwrap());
assert_eq!(string, "Hello");
sleep(std::time::Duration::from_secs(1));
string.store("World".to_string());
println!("Thread1: {}", string.cached().unwrap());
assert_eq!(string, "World");
});
let t2 = s.spawn(move || {
sleep(std::time::Duration::from_micros(100));
let mut string = String::with_load("test", client2);
println!("Thread2: {}", string.cached().unwrap());
assert_eq!(string, "Hello");
sleep(std::time::Duration::from_secs(2));
string.acquire();
println!("Thread2: {}", string.cached().unwrap());
assert_eq!(string, "World");
});
t1.join().expect("Failed to join thread1");
t2.join().expect("Failed to join thread2");
});
}sourcepub fn acquire(&mut self) -> &T
pub fn acquire(&mut self) -> &T
The get method returns a reference to the value stored in the type. Loads it from the redis directly.
Example
use types::i32;
let client = redis::Client::open("redis://localhost:6379").unwrap();
let mut i32 = i32::with_value(1, "test_add", client.clone());
i32 = i32 + i32::with_value(2, "test_add2", client);
assert_eq!(i32.acquire(), &3);Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
thread::scope(|s| {
let client = redis::Client::open("redis://localhost:6379").unwrap();
let client2 = client.clone();
let t1 = s.spawn(move || {
let mut string = String::with_value("Hello".to_string(), "test", client);
println!("Thread1: {}", string.cached().unwrap());
assert_eq!(string, "Hello");
sleep(std::time::Duration::from_secs(1));
string.store("World".to_string());
println!("Thread1: {}", string.cached().unwrap());
assert_eq!(string, "World");
});
let t2 = s.spawn(move || {
sleep(std::time::Duration::from_micros(100));
let mut string = String::with_load("test", client2);
println!("Thread2: {}", string.cached().unwrap());
assert_eq!(string, "Hello");
sleep(std::time::Duration::from_secs(2));
string.acquire();
println!("Thread2: {}", string.cached().unwrap());
assert_eq!(string, "World");
});
t1.join().expect("Failed to join thread1");
t2.join().expect("Failed to join thread2");
});
}sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
The into_inner method returns the inner value of the type. This method consumes the type and drops everything.
Example
use types::i32;
let client = redis::Client::open("redis://localhost:6379").unwrap();
let i32 = i32::with_value(3, "test_add", client.clone());
let i32_inner = i32.into_inner();
assert_eq!(i32_inner, 3);sourcepub fn cached(&self) -> Option<&T>
pub fn cached(&self) -> Option<&T>
The get method returns a reference to the value stored in the type.
Examples found in repository?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
thread::scope(|s| {
let client = redis::Client::open("redis://localhost:6379").unwrap();
let client2 = client.clone();
let t1 = s.spawn(move || {
let mut string = String::with_value("Hello".to_string(), "test", client);
println!("Thread1: {}", string.cached().unwrap());
assert_eq!(string, "Hello");
sleep(std::time::Duration::from_secs(1));
string.store("World".to_string());
println!("Thread1: {}", string.cached().unwrap());
assert_eq!(string, "World");
});
let t2 = s.spawn(move || {
sleep(std::time::Duration::from_micros(100));
let mut string = String::with_load("test", client2);
println!("Thread2: {}", string.cached().unwrap());
assert_eq!(string, "Hello");
sleep(std::time::Duration::from_secs(2));
string.acquire();
println!("Thread2: {}", string.cached().unwrap());
assert_eq!(string, "World");
});
t1.join().expect("Failed to join thread1");
t2.join().expect("Failed to join thread2");
});
}Trait Implementations§
source§impl<T> Add<RedisGeneric<T>> for RedisGeneric<T>where
T: Add<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> Add<RedisGeneric<T>> for RedisGeneric<T>where T: Add<Output = T> + Display + Serialize + DeserializeOwned,
§type Output = RedisGeneric<T>
type Output = RedisGeneric<T>
+ operator.source§impl<T> Add<T> for RedisGeneric<T>where
T: Add<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> Add<T> for RedisGeneric<T>where T: Add<Output = T> + Display + Serialize + DeserializeOwned,
source§impl<T> AddAssign<RedisGeneric<T>> for RedisGeneric<T>where
T: AddAssign + Display + Serialize + DeserializeOwned,
impl<T> AddAssign<RedisGeneric<T>> for RedisGeneric<T>where T: AddAssign + Display + Serialize + DeserializeOwned,
source§fn add_assign(&mut self, rhs: RedisGeneric<T>)
fn add_assign(&mut self, rhs: RedisGeneric<T>)
+= operation. Read moresource§impl<T> AddAssign<T> for RedisGeneric<T>where
T: AddAssign + Display + Serialize + DeserializeOwned,
impl<T> AddAssign<T> for RedisGeneric<T>where T: AddAssign + Display + Serialize + DeserializeOwned,
source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+= operation. Read moresource§impl<T> BitAnd<RedisGeneric<T>> for RedisGeneric<T>where
T: BitAnd<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> BitAnd<RedisGeneric<T>> for RedisGeneric<T>where T: BitAnd<Output = T> + Display + Serialize + DeserializeOwned,
§type Output = RedisGeneric<T>
type Output = RedisGeneric<T>
& operator.source§impl<T> BitAnd<T> for RedisGeneric<T>where
T: BitAnd<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> BitAnd<T> for RedisGeneric<T>where T: BitAnd<Output = T> + Display + Serialize + DeserializeOwned,
source§impl<T> BitOr<RedisGeneric<T>> for RedisGeneric<T>where
T: BitOr<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> BitOr<RedisGeneric<T>> for RedisGeneric<T>where T: BitOr<Output = T> + Display + Serialize + DeserializeOwned,
§type Output = RedisGeneric<T>
type Output = RedisGeneric<T>
| operator.source§impl<T> BitOr<T> for RedisGeneric<T>where
T: BitOr<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> BitOr<T> for RedisGeneric<T>where T: BitOr<Output = T> + Display + Serialize + DeserializeOwned,
source§impl<T> BitXor<RedisGeneric<T>> for RedisGeneric<T>where
T: BitXor<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> BitXor<RedisGeneric<T>> for RedisGeneric<T>where T: BitXor<Output = T> + Display + Serialize + DeserializeOwned,
§type Output = RedisGeneric<T>
type Output = RedisGeneric<T>
^ operator.source§impl<T> BitXor<T> for RedisGeneric<T>where
T: BitXor<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> BitXor<T> for RedisGeneric<T>where T: BitXor<Output = T> + Display + Serialize + DeserializeOwned,
source§impl<T: Debug> Debug for RedisGeneric<T>
impl<T: Debug> Debug for RedisGeneric<T>
source§impl<T> Deref for RedisGeneric<T>where
T: Display + Serialize + DeserializeOwned,
impl<T> Deref for RedisGeneric<T>where T: Display + Serialize + DeserializeOwned,
source§impl<T> Div<RedisGeneric<T>> for RedisGeneric<T>where
T: Div<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> Div<RedisGeneric<T>> for RedisGeneric<T>where T: Div<Output = T> + Display + Serialize + DeserializeOwned,
§type Output = RedisGeneric<T>
type Output = RedisGeneric<T>
/ operator.source§impl<T> Div<T> for RedisGeneric<T>where
T: Div<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> Div<T> for RedisGeneric<T>where T: Div<Output = T> + Display + Serialize + DeserializeOwned,
source§impl<T> Mul<RedisGeneric<T>> for RedisGeneric<T>where
T: Mul<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> Mul<RedisGeneric<T>> for RedisGeneric<T>where T: Mul<Output = T> + Display + Serialize + DeserializeOwned,
§type Output = RedisGeneric<T>
type Output = RedisGeneric<T>
* operator.source§impl<T> Mul<T> for RedisGeneric<T>where
T: Mul<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> Mul<T> for RedisGeneric<T>where T: Mul<Output = T> + Display + Serialize + DeserializeOwned,
source§impl<T: PartialEq> PartialEq<RedisGeneric<T>> for RedisGeneric<T>
impl<T: PartialEq> PartialEq<RedisGeneric<T>> for RedisGeneric<T>
source§fn eq(&self, other: &RedisGeneric<T>) -> bool
fn eq(&self, other: &RedisGeneric<T>) -> bool
self and other values to be equal, and is used
by ==.source§impl<T: PartialEq> PartialEq<T> for RedisGeneric<T>
impl<T: PartialEq> PartialEq<T> for RedisGeneric<T>
source§impl<T> Sub<RedisGeneric<T>> for RedisGeneric<T>where
T: Sub<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> Sub<RedisGeneric<T>> for RedisGeneric<T>where T: Sub<Output = T> + Display + Serialize + DeserializeOwned,
§type Output = RedisGeneric<T>
type Output = RedisGeneric<T>
- operator.source§impl<T> Sub<T> for RedisGeneric<T>where
T: Sub<Output = T> + Display + Serialize + DeserializeOwned,
impl<T> Sub<T> for RedisGeneric<T>where T: Sub<Output = T> + Display + Serialize + DeserializeOwned,
source§impl<T> SubAssign<RedisGeneric<T>> for RedisGeneric<T>where
T: SubAssign + Display + Serialize + DeserializeOwned,
impl<T> SubAssign<RedisGeneric<T>> for RedisGeneric<T>where T: SubAssign + Display + Serialize + DeserializeOwned,
source§fn sub_assign(&mut self, rhs: RedisGeneric<T>)
fn sub_assign(&mut self, rhs: RedisGeneric<T>)
-= operation. Read moresource§impl<T> SubAssign<T> for RedisGeneric<T>where
T: SubAssign + Display + Serialize + DeserializeOwned,
impl<T> SubAssign<T> for RedisGeneric<T>where T: SubAssign + Display + Serialize + DeserializeOwned,
source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-= operation. Read more