优化代码
This commit is contained in:
parent
5eb57f4570
commit
d66e45b7c3
28
library/src/cache/redis_cache.rs
vendored
28
library/src/cache/redis_cache.rs
vendored
@ -26,7 +26,7 @@ impl Default for RedisConnManager {
|
|||||||
|
|
||||||
impl RedisConnManager {
|
impl RedisConnManager {
|
||||||
pub async fn set(&self, key: &str, value: &str) -> ResResult<()> {
|
pub async fn set(&self, key: &str, value: &str) -> ResResult<()> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::set(key, value).exec_async(&mut conn).await {
|
match Cmd::set(key, value).exec_async(&mut conn).await {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -37,7 +37,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn setexp(&self, key: &str, value: &str, seconds: u64) -> ResResult<()> {
|
pub async fn setexp(&self, key: &str, value: &str, seconds: u64) -> ResResult<()> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::set_ex(key, value, seconds).exec_async(&mut conn).await {
|
match Cmd::set_ex(key, value, seconds).exec_async(&mut conn).await {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -54,7 +54,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get(&self, key: &str) -> ResResult<String> {
|
pub async fn get(&self, key: &str) -> ResResult<String> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::get(key).query_async::<String>(&mut conn).await {
|
match Cmd::get(key).query_async::<String>(&mut conn).await {
|
||||||
Ok(result) => Ok(result),
|
Ok(result) => Ok(result),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -65,7 +65,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn del(&self, key: &str) -> ResResult<()> {
|
pub async fn del(&self, key: &str) -> ResResult<()> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::del(key).query_async::<i64>(&mut conn).await {
|
match Cmd::del(key).query_async::<i64>(&mut conn).await {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -76,7 +76,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn hset(&self, key: &str, field: &str, value: &str) -> ResResult<()> {
|
pub async fn hset(&self, key: &str, field: &str, value: &str) -> ResResult<()> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::hset(key, field, value)
|
match Cmd::hset(key, field, value)
|
||||||
.query_async::<i64>(&mut conn)
|
.query_async::<i64>(&mut conn)
|
||||||
.await
|
.await
|
||||||
@ -96,7 +96,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn hset_ex(&self, key: &str, field: &str, value: &str, expire: i64) -> ResResult<()> {
|
pub async fn hset_ex(&self, key: &str, field: &str, value: &str, expire: i64) -> ResResult<()> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::hset(key, field, value)
|
match Cmd::hset(key, field, value)
|
||||||
.query_async::<i64>(&mut conn)
|
.query_async::<i64>(&mut conn)
|
||||||
.await
|
.await
|
||||||
@ -133,7 +133,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn hget(&self, key: &str, field: &str) -> ResResult<String> {
|
pub async fn hget(&self, key: &str, field: &str) -> ResResult<String> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::hget(key, field).query_async::<String>(&mut conn).await {
|
match Cmd::hget(key, field).query_async::<String>(&mut conn).await {
|
||||||
Ok(result) => Ok(result),
|
Ok(result) => Ok(result),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -144,7 +144,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn hdel(&self, key: &str, field: &str) -> ResResult<()> {
|
pub async fn hdel(&self, key: &str, field: &str) -> ResResult<()> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::hdel(key, field).query_async::<i64>(&mut conn).await {
|
match Cmd::hdel(key, field).query_async::<i64>(&mut conn).await {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -155,7 +155,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn hgetall(&self, key: &str) -> ResResult<Vec<(String, String)>> {
|
pub async fn hgetall(&self, key: &str) -> ResResult<Vec<(String, String)>> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::hgetall(key)
|
match Cmd::hgetall(key)
|
||||||
.query_async::<Vec<(String, String)>>(&mut conn)
|
.query_async::<Vec<(String, String)>>(&mut conn)
|
||||||
.await
|
.await
|
||||||
@ -169,7 +169,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn hkeys(&self, key: &str) -> ResResult<Vec<String>> {
|
pub async fn hkeys(&self, key: &str) -> ResResult<Vec<String>> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::hkeys(key).query_async::<Vec<String>>(&mut conn).await {
|
match Cmd::hkeys(key).query_async::<Vec<String>>(&mut conn).await {
|
||||||
Ok(result) => Ok(result),
|
Ok(result) => Ok(result),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -180,7 +180,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn hvals(&self, key: &str) -> ResResult<Vec<String>> {
|
pub async fn hvals(&self, key: &str) -> ResResult<Vec<String>> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::hvals(key).query_async::<Vec<String>>(&mut conn).await {
|
match Cmd::hvals(key).query_async::<Vec<String>>(&mut conn).await {
|
||||||
Ok(result) => Ok(result),
|
Ok(result) => Ok(result),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -191,7 +191,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn hlen(&self, key: &str) -> ResResult<i64> {
|
pub async fn hlen(&self, key: &str) -> ResResult<i64> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::hlen(key).query_async::<i64>(&mut conn).await {
|
match Cmd::hlen(key).query_async::<i64>(&mut conn).await {
|
||||||
Ok(result) => Ok(result),
|
Ok(result) => Ok(result),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -202,7 +202,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn expire(&self, key: &str, seconds: i64) -> ResResult<()> {
|
pub async fn expire(&self, key: &str, seconds: i64) -> ResResult<()> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::expire(key, seconds)
|
match Cmd::expire(key, seconds)
|
||||||
.query_async::<i64>(&mut conn)
|
.query_async::<i64>(&mut conn)
|
||||||
.await
|
.await
|
||||||
@ -216,7 +216,7 @@ impl RedisConnManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn ttl(&self, key: &str) -> ResResult<i64> {
|
pub async fn ttl(&self, key: &str) -> ResResult<i64> {
|
||||||
let mut conn = self.get_conn().await.unwrap();
|
let mut conn = self.get_conn().await?;
|
||||||
match Cmd::ttl(key).query_async::<i64>(&mut conn).await {
|
match Cmd::ttl(key).query_async::<i64>(&mut conn).await {
|
||||||
Ok(result) => Ok(result),
|
Ok(result) => Ok(result),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user