From cf51cf6f7424a85795bc67b3cece29c806a6d7e0 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Mon, 6 Apr 2026 20:06:14 +0200 Subject: feat(oauth): redirect --- crates/sh-util/src/cache/key.rs | 23 +++++++++++++++ crates/sh-util/src/cache/mod.rs | 2 ++ crates/sh-util/src/cache/sentinel.rs | 57 ------------------------------------ 3 files changed, 25 insertions(+), 57 deletions(-) create mode 100644 crates/sh-util/src/cache/key.rs (limited to 'crates/sh-util') diff --git a/crates/sh-util/src/cache/key.rs b/crates/sh-util/src/cache/key.rs new file mode 100644 index 0000000..41315b8 --- /dev/null +++ b/crates/sh-util/src/cache/key.rs @@ -0,0 +1,23 @@ +use redis::{ToRedisArgs, ToSingleRedisArg}; + +pub enum CacheKey<'a> { + Session(&'a str), +} + +impl ToRedisArgs for CacheKey<'_> { + fn write_redis_args(&self, out: &mut W) + where + W: ?Sized + redis::RedisWrite, + { + out.write_arg( + match self { + CacheKey::Session(id) => { + format!("session:{id}") + } + } + .as_bytes(), + ); + } +} + +impl ToSingleRedisArg for CacheKey<'_> {} diff --git a/crates/sh-util/src/cache/mod.rs b/crates/sh-util/src/cache/mod.rs index 67a5121..575e776 100644 --- a/crates/sh-util/src/cache/mod.rs +++ b/crates/sh-util/src/cache/mod.rs @@ -1,3 +1,5 @@ +mod key; +pub use key::*; mod cluster; mod sentinel; pub use sentinel::SentinelConfig; diff --git a/crates/sh-util/src/cache/sentinel.rs b/crates/sh-util/src/cache/sentinel.rs index e52b043..5406c4d 100644 --- a/crates/sh-util/src/cache/sentinel.rs +++ b/crates/sh-util/src/cache/sentinel.rs @@ -1,12 +1,3 @@ -use futures_util::lock::Mutex; -use redis::{ - ErrorKind, IntoConnectionInfo, RedisError, - sentinel::{SentinelClient, SentinelNodeConnectionInfo, SentinelServerType}, -}; -use serde::Deserialize; - -struct LockedSentinelClient(pub(crate) Mutex); - #[derive(Clone, Debug, Eq, PartialEq)] pub struct SentinelConfig { pub service_name: String, @@ -16,51 +7,3 @@ pub struct SentinelConfig { pub redis_password: String, pub redis_use_resp3: bool, } - -/// ConnectionManager that implements `bb8::ManageConnection` and supports -/// asynchronous Sentinel connections via `redis::sentinel::SentinelClient` -pub struct RedisSentinelConnectionManager { - client: LockedSentinelClient, -} - -impl RedisSentinelConnectionManager { - pub fn new( - info: Vec, - service_name: String, - node_connection_info: Option, - ) -> Result { - Ok(RedisSentinelConnectionManager { - client: LockedSentinelClient(Mutex::new(SentinelClient::build( - info, - service_name, - node_connection_info, - SentinelServerType::Master, - )?)), - }) - } -} - -impl bb8::ManageConnection for RedisSentinelConnectionManager { - type Connection = redis::aio::MultiplexedConnection; - type Error = RedisError; - - async fn connect(&self) -> Result { - self.client.0.lock().await.get_async_connection().await - } - - async fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error> { - let pong: String = redis::cmd("PING").query_async(conn).await?; - match pong.as_str() { - "PONG" => Ok(()), - _ => Err(( - ErrorKind::Server(redis::ServerErrorKind::ResponseError), - "ping request", - ) - .into()), - } - } - - fn has_broken(&self, _: &mut Self::Connection) -> bool { - false - } -} -- cgit v1.2.3