Commit 175f2fc3 by qlintonger xeno

redis-int+1

parent 0849b979
...@@ -53,10 +53,6 @@ async fn update_connected_redis() { ...@@ -53,10 +53,6 @@ async fn update_connected_redis() {
let connections = CONNECTIONS.lock().await; let connections = CONNECTIONS.lock().await;
let from_ids: Vec<String> = connections.keys().cloned().collect(); let from_ids: Vec<String> = connections.keys().cloned().collect();
let mut con = REDIS_POOL.get_connection().expect("Failed to get Redis connection"); let mut con = REDIS_POOL.get_connection().expect("Failed to get Redis connection");
// 先清空原有的列表
if let Err(e) = con.del::<_, ()>("connected") {
println!("Failed to delete old connected list in Redis: {}", e);
}
// 将每个 fromId 依次添加到列表中 // 将每个 fromId 依次添加到列表中
for from_id in from_ids { for from_id in from_ids {
if let Err(e) = con.rpush::<_, _, ()>("connected", from_id) { if let Err(e) = con.rpush::<_, _, ()>("connected", from_id) {
...@@ -132,7 +128,7 @@ pub(crate) async fn handle_client(stream: tokio::net::TcpStream) -> Result<(), E ...@@ -132,7 +128,7 @@ pub(crate) async fn handle_client(stream: tokio::net::TcpStream) -> Result<(), E
let from_id = from_id.clone(); let from_id = from_id.clone();
// 从 Redis 连接池获取连接 // 从 Redis 连接池获取连接
let mut con = REDIS_POOL.get_connection().expect("Failed to get Redis connection"); let con = REDIS_POOL.get_connection().expect("Failed to get Redis connection");
// 检查 Redis 中是否已经存在该 fromId // 检查 Redis 中是否已经存在该 fromId
close_existing_connection(&from_id).await; close_existing_connection(&from_id).await;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment