变更代码目录

This commit is contained in:
李运家 2024-10-12 09:57:53 +08:00
parent d06df32c0c
commit bb547230eb
10 changed files with 16 additions and 14 deletions

View File

@ -20,7 +20,8 @@ expires = 1800
refresh_expires = 3600 refresh_expires = 3600
[redis] [redis]
url = "47.95.198.7:33000" # url = "47.95.198.7:33000"
url = "127.0.0.1:33001"
password = "3aB7kRt9pDf1nQzW" password = "3aB7kRt9pDf1nQzW"
db = 0 db = 0

View File

@ -10,7 +10,7 @@ use moka::{
}; };
use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde::{de::DeserializeOwned, Deserialize, Serialize};
use crate::core::redis::REDIS_CONN; use crate::cache::redis_cache::REDIS_CACHE;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CacheAccount { pub struct CacheAccount {
@ -124,7 +124,7 @@ struct RedisCache {
impl RedisCache { impl RedisCache {
/// 向redis缓存Hash中插入数据 /// 向redis缓存Hash中插入数据
pub async fn insert(&self) { pub async fn insert(&self) {
match REDIS_CONN match REDIS_CACHE
.hset_ex( .hset_ex(
&self.cache_type, &self.cache_type,
&self.cache_key, &self.cache_key,
@ -143,7 +143,7 @@ impl RedisCache {
/// 从redis缓存Hash中获取数据 /// 从redis缓存Hash中获取数据
pub async fn get(cache_type: Arc<String>) -> Vec<RedisCache> { pub async fn get(cache_type: Arc<String>) -> Vec<RedisCache> {
let mut result = Vec::new(); let mut result = Vec::new();
match REDIS_CONN.hgetall(&cache_type).await { match REDIS_CACHE.hgetall(&cache_type).await {
Ok(cache_datas) => { Ok(cache_datas) => {
for (key, value) in cache_datas { for (key, value) in cache_datas {
let cache_data = RedisCache { let cache_data = RedisCache {
@ -164,7 +164,7 @@ impl RedisCache {
/// 从redis缓存Hash中删除数据 /// 从redis缓存Hash中删除数据
pub async fn remove(&self) { pub async fn remove(&self) {
match REDIS_CONN.hdel(&self.cache_type, &self.cache_key).await { match REDIS_CACHE.hdel(&self.cache_type, &self.cache_key).await {
Ok(_) => { Ok(_) => {
tracing::info!("从缓存Hash删除数据成功"); tracing::info!("从缓存Hash删除数据成功");
} }

2
library/src/cache/mod.rs vendored Normal file
View File

@ -0,0 +1,2 @@
pub mod inner_cache;
pub mod redis_cache;

View File

@ -195,5 +195,5 @@ impl RedisConnManager {
} }
lazy_static! { lazy_static! {
pub static ref REDIS_CONN: RedisConnManager = RedisConnManager::default(); pub static ref REDIS_CACHE: RedisConnManager = RedisConnManager::default();
} }

View File

@ -1,4 +1,3 @@
pub mod config; pub mod config;
pub mod logger; pub mod logger;
pub mod db; pub mod db;
pub mod redis;

View File

@ -5,10 +5,10 @@ pub mod model;
pub mod middleware; pub mod middleware;
pub mod token; pub mod token;
pub mod social; pub mod social;
pub mod cache;
pub mod context; pub mod context;
pub mod task; pub mod task;
pub mod utils; pub mod utils;
pub mod extractor; pub mod extractor;
pub mod router; pub mod router;
pub mod typed_router; pub mod typed_router;
pub mod cache;

View File

@ -5,7 +5,7 @@ use http::header;
use i18n::{message, message_ids::MessageId}; use i18n::{message, message_ids::MessageId};
use jsonwebtoken::{decode, DecodingKey, Validation}; use jsonwebtoken::{decode, DecodingKey, Validation};
use crate::{cache::LOGIN_ACCOUNT_CACHE, config, context::Context, model::response::ResErr, token::Claims, utils::request_util}; use crate::{cache::inner_cache::LOGIN_ACCOUNT_CACHE, config, context::Context, model::response::ResErr, token::Claims, utils::request_util};
const WHITE_LIST: &[(&str, &str)] = &[ const WHITE_LIST: &[(&str, &str)] = &[
("POST", "/account/sys"), ("POST", "/account/sys"),

View File

@ -6,7 +6,7 @@ use domain::entities::account::Account;
use domain::vo::account::{LoginAccount, RefreshTokenResult}; use domain::vo::account::{LoginAccount, RefreshTokenResult};
use i18n::message; use i18n::message;
use i18n::message_ids::MessageId; use i18n::message_ids::MessageId;
use library::cache::{CacheAccount, LOGIN_ACCOUNT_CACHE}; use library::cache::inner_cache::{CacheAccount, LOGIN_ACCOUNT_CACHE};
use library::context::Context; use library::context::Context;
use library::model::response::ResErr::ErrPerm; use library::model::response::ResErr::ErrPerm;
use library::model::response::{ResErr, ResResult}; use library::model::response::{ResErr, ResResult};

View File

@ -11,7 +11,7 @@ use i18n::{
message_ids::MessageId, message_ids::MessageId,
}; };
use library::{ use library::{
cache::{CacheAccount, LOGIN_ACCOUNT_CACHE}, context::Context, db, model::response::{ResErr, ResResult}, token::{generate_refresh_token, generate_token} cache::inner_cache::{CacheAccount, LOGIN_ACCOUNT_CACHE}, context::Context, db, model::response::{ResErr, ResResult}, token::{generate_refresh_token, generate_token}
}; };
/// 登录, 使用账号和密码 /// 登录, 使用账号和密码

View File

@ -8,7 +8,7 @@ async fn main() {
// 初始化日志、数据库连接池、内存缓存;初始化顺序不可变更 // 初始化日志、数据库连接池、内存缓存;初始化顺序不可变更
let (_std_guard, _file_guard) = library::core::logger::init_log(); let (_std_guard, _file_guard) = library::core::logger::init_log();
library::core::db::init_database().await; library::core::db::init_database().await;
library::cache::init_cache().await; library::cache::inner_cache::init_cache().await;
server::serve().await; server::serve().await;
} }