diff --git a/Cargo.toml b/Cargo.toml index d7576283..ecbe94a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,6 @@ description = "The CdsCTF project is an open-source, high-performance, Jeopardy- async-trait = { version = "0.1" } tokio = { version = "1.41", features = ["full"] } tokio-util = { version = "0.7.12" } -tokio-rustls = { version = "0.26.0", features = ["ring"] } futures = { version = "^0.3" } futures-util = { version = "^0.3" } tower = { version = "0.5" } @@ -25,13 +24,6 @@ axum = { version = "0.7", features = [ "tracing", "json", ] } -axum-extra = { version = "0.9", features = [ - "typed-header", - "query", - "multipart", - "typed-routing", - "async-read-body", -] } rust-embed = { version = "8.5" } mime = { version = "0.3" } mime_guess = { version = "2.0" } @@ -76,14 +68,13 @@ sea-orm = { version = "1.1", features = [ "with-json", "runtime-tokio-rustls", ] } -sea-orm-migration = { version = "1.1" } # Message Queue async-nats = { version = "0.38" } # Cache -fred = { version = "9.4", features = [ - "enable-rustls", +fred = { version = "10.0", features = [ + "enable-rustls-ring", "dns", "mocks", "monitor", @@ -104,7 +95,7 @@ reqwest = { version = "0.12", features = [ "json", "rustls-tls", ], default-features = false } -sysinfo = { version = "0.32.0" } +sysinfo = { version = "0.32.1" } tempfile = { version = "3.14.0" } image = { version = "0.25.5" } webp = { version = "0.3.0", features = ["image"] } diff --git a/src/cache/mod.rs b/src/cache/mod.rs index c340de9e..8ebc3bbd 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -1,8 +1,8 @@ use std::fmt::Display; use fred::{ - prelude::{ClientLike, KeysInterface, RedisClient}, - types::{Expiration, RedisConfig, RedisKey}, + prelude::{Client, ClientLike, KeysInterface}, + types::{config::Config, Expiration, Key}, }; use once_cell::sync::OnceCell; use serde::{Deserialize, Serialize}; @@ -12,13 +12,13 @@ use traits::CacheError; pub mod traits; -static CLIENT: OnceCell = OnceCell::new(); +static CLIENT: OnceCell = OnceCell::new(); -fn get_client() -> RedisClient { +fn get_client() -> Client { CLIENT.get().unwrap().clone() } -pub async fn get(key: impl Into + Send + Display) -> Result, CacheError> +pub async fn get(key: impl Into + Send + Display) -> Result, CacheError> where T: for<'de> Deserialize<'de>, { let result = get_client().get::, _>(key).await?; @@ -28,9 +28,7 @@ where } } -pub async fn get_del( - key: impl Into + Send + Display, -) -> Result, CacheError> +pub async fn get_del(key: impl Into + Send + Display) -> Result, CacheError> where T: for<'de> Deserialize<'de>, { let result = get_client().getdel::, _>(key).await?; @@ -41,7 +39,7 @@ where } pub async fn set( - key: impl Into + Send + Display, value: impl Serialize + Send, + key: impl Into + Send + Display, value: impl Serialize + Send, ) -> Result<(), CacheError> { let value = serde_json::to_string(&value)?; get_client().set(key, value, None, None, false).await?; @@ -50,7 +48,7 @@ pub async fn set( } pub async fn set_ex( - key: impl Into + Send + Display, value: impl Serialize + Send, expire: u64, + key: impl Into + Send + Display, value: impl Serialize + Send, expire: u64, ) -> Result<(), CacheError> { let value = serde_json::to_string(&value)?; get_client() @@ -67,8 +65,8 @@ pub async fn flush() -> Result<(), CacheError> { } pub async fn init() { - let config = RedisConfig::from_url(&crate::env::get_env().cache.url).unwrap(); - let client = RedisClient::new(config, None, None, None); + let config = Config::from_url(&crate::env::get_env().cache.url).unwrap(); + let client = Client::new(config, None, None, None); client.init().await.unwrap(); CLIENT.set(client).unwrap(); diff --git a/src/cache/traits.rs b/src/cache/traits.rs index 9236da6b..60ea826f 100644 --- a/src/cache/traits.rs +++ b/src/cache/traits.rs @@ -1,10 +1,9 @@ -use fred::error::RedisError; use thiserror::Error; #[derive(Debug, Error)] pub enum CacheError { #[error("redis error: {0}")] - RedisError(#[from] RedisError), + RedisError(#[from] fred::error::Error), #[error("serde_json error: {0}")] SerdeJsonError(#[from] serde_json::Error), } diff --git a/src/cluster/mod.rs b/src/cluster/mod.rs index 4de192f5..a1b5b26a 100644 --- a/src/cluster/mod.rs +++ b/src/cluster/mod.rs @@ -1,4 +1,4 @@ -pub(crate)mod traits; +pub mod traits; use std::{collections::BTreeMap, process, sync::OnceLock, time::Duration}; @@ -19,6 +19,7 @@ use kube::{ use once_cell::sync::OnceCell; use tokio_util::codec::Framed; use tracing::{error, info}; + use crate::cluster::traits::ClusterError; static K8S_CLIENT: OnceCell = OnceCell::new();