Struct AsyncCache

Source
pub struct AsyncCache { /* private fields */ }

Implementations§

Source§

impl AsyncCache

Source

pub async fn new(config: RedisConfig<'_>) -> RedisResult<Self>

Examples found in repository?
examples/async.rs (line 6)
5async fn main() {
6    let ca = AsyncCache::new(RedisConfig::new("192.168.100.5:6379", 1))
7        .await
8        .unwrap();
9    let mut ca1 = ca.clone();
10    let f1 = tokio::spawn(async move {
11        ca1.set("AsyncKey1", "AsyncValue1").await.unwrap();
12        let val: String = ca1.get("AsyncKey1").await.unwrap();
13        println!("val: {val}");
14        ca1.del("AsyncKey1").await.unwrap();
15    });
16    let mut ca2 = ca.clone();
17    let f2 = tokio::spawn(async move {
18        ca2.hsetall(
19            UserKey,
20            User {
21                id: "123".into(),
22                name: "abc".into(),
23                age: 321,
24            },
25        )
26        .await
27        .unwrap();
28        let u: User = ca2.hgetall(UserKey).await.unwrap();
29        println!("user: {:?}", u);
30        ca2.del(UserKey).await.unwrap();
31    });
32
33    let _ = tokio::join!(f1, f2);
34}
Source§

impl AsyncCache

Source

pub async fn get<K, V>(&mut self, key: K) -> RedisResult<V>

Examples found in repository?
examples/async.rs (line 12)
5async fn main() {
6    let ca = AsyncCache::new(RedisConfig::new("192.168.100.5:6379", 1))
7        .await
8        .unwrap();
9    let mut ca1 = ca.clone();
10    let f1 = tokio::spawn(async move {
11        ca1.set("AsyncKey1", "AsyncValue1").await.unwrap();
12        let val: String = ca1.get("AsyncKey1").await.unwrap();
13        println!("val: {val}");
14        ca1.del("AsyncKey1").await.unwrap();
15    });
16    let mut ca2 = ca.clone();
17    let f2 = tokio::spawn(async move {
18        ca2.hsetall(
19            UserKey,
20            User {
21                id: "123".into(),
22                name: "abc".into(),
23                age: 321,
24            },
25        )
26        .await
27        .unwrap();
28        let u: User = ca2.hgetall(UserKey).await.unwrap();
29        println!("user: {:?}", u);
30        ca2.del(UserKey).await.unwrap();
31    });
32
33    let _ = tokio::join!(f1, f2);
34}
Source

pub async fn set<K, V>(&mut self, key: K, value: V) -> RedisResult<()>
where K: ToRedisArgs, V: ToRedisArgs,

Examples found in repository?
examples/async.rs (line 11)
5async fn main() {
6    let ca = AsyncCache::new(RedisConfig::new("192.168.100.5:6379", 1))
7        .await
8        .unwrap();
9    let mut ca1 = ca.clone();
10    let f1 = tokio::spawn(async move {
11        ca1.set("AsyncKey1", "AsyncValue1").await.unwrap();
12        let val: String = ca1.get("AsyncKey1").await.unwrap();
13        println!("val: {val}");
14        ca1.del("AsyncKey1").await.unwrap();
15    });
16    let mut ca2 = ca.clone();
17    let f2 = tokio::spawn(async move {
18        ca2.hsetall(
19            UserKey,
20            User {
21                id: "123".into(),
22                name: "abc".into(),
23                age: 321,
24            },
25        )
26        .await
27        .unwrap();
28        let u: User = ca2.hgetall(UserKey).await.unwrap();
29        println!("user: {:?}", u);
30        ca2.del(UserKey).await.unwrap();
31    });
32
33    let _ = tokio::join!(f1, f2);
34}
Source

pub async fn del<K>(&mut self, key: K) -> RedisResult<()>
where K: ToRedisArgs,

Examples found in repository?
examples/async.rs (line 14)
5async fn main() {
6    let ca = AsyncCache::new(RedisConfig::new("192.168.100.5:6379", 1))
7        .await
8        .unwrap();
9    let mut ca1 = ca.clone();
10    let f1 = tokio::spawn(async move {
11        ca1.set("AsyncKey1", "AsyncValue1").await.unwrap();
12        let val: String = ca1.get("AsyncKey1").await.unwrap();
13        println!("val: {val}");
14        ca1.del("AsyncKey1").await.unwrap();
15    });
16    let mut ca2 = ca.clone();
17    let f2 = tokio::spawn(async move {
18        ca2.hsetall(
19            UserKey,
20            User {
21                id: "123".into(),
22                name: "abc".into(),
23                age: 321,
24            },
25        )
26        .await
27        .unwrap();
28        let u: User = ca2.hgetall(UserKey).await.unwrap();
29        println!("user: {:?}", u);
30        ca2.del(UserKey).await.unwrap();
31    });
32
33    let _ = tokio::join!(f1, f2);
34}
Source

pub async fn incr<K>(&mut self, key: K) -> RedisResult<i32>
where K: ToRedisArgs,

Source

pub async fn exists<K>(&mut self, key: K) -> RedisResult<bool>
where K: ToRedisArgs,

Source

pub async fn expire<K>(&mut self, key: K, sec: i32) -> RedisResult<()>
where K: ToRedisArgs,

Source

pub async fn sadd<K, V>(&mut self, key: K, value: &[V]) -> RedisResult<()>
where K: ToRedisArgs, V: ToRedisArgs,

Source

pub async fn smembers<K, V>(&mut self, key: K) -> RedisResult<Vec<V>>

Source

pub async fn srem<K, V>(&mut self, key: K, values: &[V]) -> RedisResult<()>
where K: ToRedisArgs, V: ToRedisArgs,

Source

pub async fn scard<K>(&mut self, key: K) -> RedisResult<usize>
where K: ToRedisArgs,

Source

pub async fn sismember<K, V>(&mut self, key: K, value: V) -> RedisResult<bool>
where K: ToRedisArgs, V: ToRedisArgs,

Source

pub async fn hset<K, F, V>( &mut self, key: K, field: F, value: V, ) -> RedisResult<()>

Source

pub async fn hget<K, F, V>(&mut self, key: K, field: F) -> RedisResult<V>

Source

pub async fn hmset<K, F, V>( &mut self, key: K, values: &[(F, V)], ) -> RedisResult<()>

Source

pub async fn hmget<K, F, V>(&mut self, key: K, fields: &[F]) -> RedisResult<V>

Source

pub async fn hsetall<K, V>(&mut self, key: K, value: V) -> RedisResult<()>
where K: ToRedisArgs, V: ToRedisArgs,

Examples found in repository?
examples/async.rs (lines 18-25)
5async fn main() {
6    let ca = AsyncCache::new(RedisConfig::new("192.168.100.5:6379", 1))
7        .await
8        .unwrap();
9    let mut ca1 = ca.clone();
10    let f1 = tokio::spawn(async move {
11        ca1.set("AsyncKey1", "AsyncValue1").await.unwrap();
12        let val: String = ca1.get("AsyncKey1").await.unwrap();
13        println!("val: {val}");
14        ca1.del("AsyncKey1").await.unwrap();
15    });
16    let mut ca2 = ca.clone();
17    let f2 = tokio::spawn(async move {
18        ca2.hsetall(
19            UserKey,
20            User {
21                id: "123".into(),
22                name: "abc".into(),
23                age: 321,
24            },
25        )
26        .await
27        .unwrap();
28        let u: User = ca2.hgetall(UserKey).await.unwrap();
29        println!("user: {:?}", u);
30        ca2.del(UserKey).await.unwrap();
31    });
32
33    let _ = tokio::join!(f1, f2);
34}
Source

pub async fn hgetall<K, V>(&mut self, key: K) -> RedisResult<V>

Examples found in repository?
examples/async.rs (line 28)
5async fn main() {
6    let ca = AsyncCache::new(RedisConfig::new("192.168.100.5:6379", 1))
7        .await
8        .unwrap();
9    let mut ca1 = ca.clone();
10    let f1 = tokio::spawn(async move {
11        ca1.set("AsyncKey1", "AsyncValue1").await.unwrap();
12        let val: String = ca1.get("AsyncKey1").await.unwrap();
13        println!("val: {val}");
14        ca1.del("AsyncKey1").await.unwrap();
15    });
16    let mut ca2 = ca.clone();
17    let f2 = tokio::spawn(async move {
18        ca2.hsetall(
19            UserKey,
20            User {
21                id: "123".into(),
22                name: "abc".into(),
23                age: 321,
24            },
25        )
26        .await
27        .unwrap();
28        let u: User = ca2.hgetall(UserKey).await.unwrap();
29        println!("user: {:?}", u);
30        ca2.del(UserKey).await.unwrap();
31    });
32
33    let _ = tokio::join!(f1, f2);
34}
Source

pub async fn hexists<K, F>(&mut self, key: K, field: F) -> RedisResult<bool>
where K: ToRedisArgs, F: ToRedisArgs,

Source

pub async fn hdel<K, F>(&mut self, key: K, fields: &[F]) -> RedisResult<()>
where K: ToRedisArgs, F: ToRedisArgs,

Source

pub async fn zadd<K, S, M>( &mut self, key: K, items: &[(S, M)], ) -> RedisResult<()>

Source

pub async fn zrange_by_score<K, M, V>( &mut self, key: K, min: M, max: M, ) -> RedisResult<Vec<V>>

Source

pub async fn zrevrange_by_score<K, M, V>( &mut self, key: K, max: M, min: M, ) -> RedisResult<Vec<V>>

Source

pub async fn zrem<K, M>(&mut self, key: K, items: &[M]) -> RedisResult<()>
where K: ToRedisArgs, M: ToRedisArgs,

Trait Implementations§

Source§

impl Clone for AsyncCache

Source§

fn clone(&self) -> AsyncCache

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,