pub struct AsyncCache { /* private fields */ }
Implementations§
Source§impl AsyncCache
impl AsyncCache
Sourcepub async fn new(config: RedisConfig<'_>) -> RedisResult<Self>
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
impl AsyncCache
Sourcepub async fn get<K, V>(&mut self, key: K) -> RedisResult<V>where
K: ToRedisArgs,
V: FromRedisValue,
pub async fn get<K, V>(&mut self, key: K) -> RedisResult<V>where
K: ToRedisArgs,
V: FromRedisValue,
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}
Sourcepub async fn set<K, V>(&mut self, key: K, value: V) -> RedisResult<()>where
K: ToRedisArgs,
V: ToRedisArgs,
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}
Sourcepub async fn del<K>(&mut self, key: K) -> RedisResult<()>where
K: ToRedisArgs,
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}
pub async fn incr<K>(&mut self, key: K) -> RedisResult<i32>where
K: ToRedisArgs,
pub async fn exists<K>(&mut self, key: K) -> RedisResult<bool>where
K: ToRedisArgs,
pub async fn expire<K>(&mut self, key: K, sec: i32) -> RedisResult<()>where
K: ToRedisArgs,
pub async fn sadd<K, V>(&mut self, key: K, value: &[V]) -> RedisResult<()>where
K: ToRedisArgs,
V: ToRedisArgs,
pub async fn smembers<K, V>(&mut self, key: K) -> RedisResult<Vec<V>>where
K: ToRedisArgs,
V: FromRedisValue,
pub async fn srem<K, V>(&mut self, key: K, values: &[V]) -> RedisResult<()>where
K: ToRedisArgs,
V: ToRedisArgs,
pub async fn scard<K>(&mut self, key: K) -> RedisResult<usize>where
K: ToRedisArgs,
pub async fn sismember<K, V>(&mut self, key: K, value: V) -> RedisResult<bool>where
K: ToRedisArgs,
V: ToRedisArgs,
pub async fn hset<K, F, V>( &mut self, key: K, field: F, value: V, ) -> RedisResult<()>
pub async fn hget<K, F, V>(&mut self, key: K, field: F) -> RedisResult<V>
pub async fn hmset<K, F, V>( &mut self, key: K, values: &[(F, V)], ) -> RedisResult<()>
pub async fn hmget<K, F, V>(&mut self, key: K, fields: &[F]) -> RedisResult<V>
Sourcepub async fn hsetall<K, V>(&mut self, key: K, value: V) -> RedisResult<()>where
K: ToRedisArgs,
V: ToRedisArgs,
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}
Sourcepub async fn hgetall<K, V>(&mut self, key: K) -> RedisResult<V>where
K: ToRedisArgs,
V: FromRedisValue,
pub async fn hgetall<K, V>(&mut self, key: K) -> RedisResult<V>where
K: ToRedisArgs,
V: FromRedisValue,
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}
pub async fn hexists<K, F>(&mut self, key: K, field: F) -> RedisResult<bool>where
K: ToRedisArgs,
F: ToRedisArgs,
pub async fn hdel<K, F>(&mut self, key: K, fields: &[F]) -> RedisResult<()>where
K: ToRedisArgs,
F: ToRedisArgs,
pub async fn zadd<K, S, M>( &mut self, key: K, items: &[(S, M)], ) -> RedisResult<()>
pub async fn zrange_by_score<K, M, V>( &mut self, key: K, min: M, max: M, ) -> RedisResult<Vec<V>>
pub async fn zrevrange_by_score<K, M, V>( &mut self, key: K, max: M, min: M, ) -> RedisResult<Vec<V>>
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
impl Clone for AsyncCache
Source§fn clone(&self) -> AsyncCache
fn clone(&self) -> AsyncCache
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for AsyncCache
impl RefUnwindSafe for AsyncCache
impl Send for AsyncCache
impl Sync for AsyncCache
impl Unpin for AsyncCache
impl UnwindSafe for AsyncCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more