Skip to content

Commit

Permalink
Add some functions for redis client.
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Jun 16, 2022
1 parent d1428e0 commit f6b2123
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tardis"
version = "0.1.0-alpha10"
version = "0.1.0-alpha11"
authors = ["gudaoxuri <[email protected]>"]
description = "Elegant, clean Rust development framework"
keywords = ["http", "database", "web", "redis", "mq"]
Expand Down
14 changes: 14 additions & 0 deletions src/cache/cache_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ impl TardisCacheClient {
(*self.con.lock().await).hlen(key).await
}

pub async fn flushdb(&self) -> RedisResult<()> {
match redis::cmd("FLUSHDB").query_async(&mut (*self.con.lock().await)).await {
Ok(()) => Ok(()),
Err(e) => Err(e),
}
}

pub async fn flushall(&self) -> RedisResult<()> {
match redis::cmd("FLUSHALL").query_async(&mut (*self.con.lock().await)).await {
Ok(()) => Ok(()),
Err(e) => Err(e),
}
}

// custom
pub async fn cmd(&self) -> MutexGuard<'_, Connection> {
self.con.lock().await
Expand Down
7 changes: 7 additions & 0 deletions tests/test_cache_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ async fn test_cache_client() -> TardisResult<()> {
.await
.unwrap();

// flush

client.set("flush_test", "测试").await?;
assert!(client.exists("flush_test").await?);
client.flushdb().await?;
assert!(!client.exists("flush_test").await?);

Ok(())
})
.await
Expand Down

0 comments on commit f6b2123

Please sign in to comment.