pub struct ConnectionPool { /* private fields */ }Expand description
LRU 连接池
Implementations§
Source§impl ConnectionPool
impl ConnectionPool
pub fn new(config: PoolConfig) -> Self
Sourcepub fn config(&self) -> &PoolConfig
pub fn config(&self) -> &PoolConfig
获取配置
Sourcepub async fn admit(
&self,
connection_id: impl Into<String>,
now_ms: i64,
) -> AdmitResult
pub async fn admit( &self, connection_id: impl Into<String>, now_ms: i64, ) -> AdmitResult
尝试将连接加入池中。
- 若已存在,返回 AlreadyExists
- 若池已满,淘汰 LRU 末尾连接后接纳
- 否则接纳
Sourcepub async fn remove(&self, connection_id: &str) -> Option<PooledConnection>
pub async fn remove(&self, connection_id: &str) -> Option<PooledConnection>
移除连接
Sourcepub async fn record_sent(&self, connection_id: &str) -> bool
pub async fn record_sent(&self, connection_id: &str) -> bool
记录发送消息
Sourcepub async fn record_received(&self, connection_id: &str) -> bool
pub async fn record_received(&self, connection_id: &str) -> bool
记录接收消息
Sourcepub async fn get(&self, connection_id: &str) -> Option<PooledConnection>
pub async fn get(&self, connection_id: &str) -> Option<PooledConnection>
获取连接
Sourcepub async fn find_by_user(&self, user_id: i64) -> Vec<PooledConnection>
pub async fn find_by_user(&self, user_id: i64) -> Vec<PooledConnection>
按用户 ID 查询连接
Sourcepub async fn evict_idle(&self, idle_threshold_ms: i64, now_ms: i64) -> usize
pub async fn evict_idle(&self, idle_threshold_ms: i64, now_ms: i64) -> usize
清理空闲超过指定时长的连接,返回被清理的数量
Sourcepub async fn lru_order_list(&self) -> Vec<String>
pub async fn lru_order_list(&self) -> Vec<String>
获取 LRU 顺序的连接 ID 列表(最近活跃在前)
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ConnectionPool
impl !UnwindSafe for ConnectionPool
impl Freeze for ConnectionPool
impl Send for ConnectionPool
impl Sync for ConnectionPool
impl Unpin for ConnectionPool
impl UnsafeUnpin for ConnectionPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more