diff --git a/app.toml b/app.toml index 346ee11..884dde3 100644 --- a/app.toml +++ b/app.toml @@ -20,7 +20,8 @@ expires = 1800 refresh_expires = 3600 [redis] -url = "47.95.198.7:33000" +# url = "47.95.198.7:33000" +url = "127.0.0.1:33001" password = "3aB7kRt9pDf1nQzW" db = 0 diff --git a/library/src/cache.rs b/library/src/cache/inner_cache.rs similarity index 96% rename from library/src/cache.rs rename to library/src/cache/inner_cache.rs index f02738a..c66bbe8 100644 --- a/library/src/cache.rs +++ b/library/src/cache/inner_cache.rs @@ -10,7 +10,7 @@ use moka::{ }; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use crate::core::redis::REDIS_CONN; +use crate::cache::redis_cache::REDIS_CACHE; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct CacheAccount { @@ -124,7 +124,7 @@ struct RedisCache { impl RedisCache { /// 向redis缓存Hash中插入数据 pub async fn insert(&self) { - match REDIS_CONN + match REDIS_CACHE .hset_ex( &self.cache_type, &self.cache_key, @@ -143,7 +143,7 @@ impl RedisCache { /// 从redis缓存Hash中获取数据 pub async fn get(cache_type: Arc) -> Vec { let mut result = Vec::new(); - match REDIS_CONN.hgetall(&cache_type).await { + match REDIS_CACHE.hgetall(&cache_type).await { Ok(cache_datas) => { for (key, value) in cache_datas { let cache_data = RedisCache { @@ -164,7 +164,7 @@ impl RedisCache { /// 从redis缓存Hash中删除数据 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(_) => { tracing::info!("从缓存Hash删除数据成功"); } diff --git a/library/src/cache/mod.rs b/library/src/cache/mod.rs new file mode 100644 index 0000000..6edfaa1 --- /dev/null +++ b/library/src/cache/mod.rs @@ -0,0 +1,2 @@ +pub mod inner_cache; +pub mod redis_cache; \ No newline at end of file diff --git a/library/src/core/redis.rs b/library/src/cache/redis_cache.rs similarity index 98% rename from library/src/core/redis.rs rename to library/src/cache/redis_cache.rs index 2d4930b..528100f 100644 --- a/library/src/core/redis.rs +++ b/library/src/cache/redis_cache.rs @@ -195,5 +195,5 @@ impl RedisConnManager { } lazy_static! { - pub static ref REDIS_CONN: RedisConnManager = RedisConnManager::default(); + pub static ref REDIS_CACHE: RedisConnManager = RedisConnManager::default(); } \ No newline at end of file diff --git a/library/src/core/mod.rs b/library/src/core/mod.rs index 5cc2f1b..5b9a69f 100644 --- a/library/src/core/mod.rs +++ b/library/src/core/mod.rs @@ -1,4 +1,3 @@ pub mod config; pub mod logger; -pub mod db; -pub mod redis; \ No newline at end of file +pub mod db; \ No newline at end of file diff --git a/library/src/lib.rs b/library/src/lib.rs index 67c672f..b3c54a5 100644 --- a/library/src/lib.rs +++ b/library/src/lib.rs @@ -5,10 +5,10 @@ pub mod model; pub mod middleware; pub mod token; pub mod social; -pub mod cache; pub mod context; pub mod task; pub mod utils; pub mod extractor; pub mod router; -pub mod typed_router; \ No newline at end of file +pub mod typed_router; +pub mod cache; \ No newline at end of file diff --git a/library/src/middleware/req_ctx.rs b/library/src/middleware/req_ctx.rs index c679405..a713fc2 100644 --- a/library/src/middleware/req_ctx.rs +++ b/library/src/middleware/req_ctx.rs @@ -5,7 +5,7 @@ use http::header; use i18n::{message, message_ids::MessageId}; 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)] = &[ ("POST", "/account/sys"), diff --git a/server/src/service/account_service.rs b/server/src/service/account_service.rs index ce46eb6..594e422 100644 --- a/server/src/service/account_service.rs +++ b/server/src/service/account_service.rs @@ -6,7 +6,7 @@ use domain::entities::account::Account; use domain::vo::account::{LoginAccount, RefreshTokenResult}; use i18n::message; 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::model::response::ResErr::ErrPerm; use library::model::response::{ResErr, ResResult}; diff --git a/server/src/service/sys_account_service.rs b/server/src/service/sys_account_service.rs index 330eea0..2835609 100644 --- a/server/src/service/sys_account_service.rs +++ b/server/src/service/sys_account_service.rs @@ -11,7 +11,7 @@ use i18n::{ message_ids::MessageId, }; 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} }; /// 登录, 使用账号和密码 diff --git a/src/main.rs b/src/main.rs index 739adbc..acb4fd1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ async fn main() { // 初始化日志、数据库连接池、内存缓存;初始化顺序不可变更 let (_std_guard, _file_guard) = library::core::logger::init_log(); library::core::db::init_database().await; - library::cache::init_cache().await; + library::cache::inner_cache::init_cache().await; server::serve().await; }