feat(redis): improve key detail auto-refresh and TTL polling
This commit is contained in:
15 files changed
+540
-106
No files matched your search
@@ -2358,6 +2358,18 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
/// Read only a key's TTL without loading its value or collection members.
|
||||
///
|
||||
/// Redis returns `-2` for a missing key and `-1` for a key without an expiry;
|
||||
/// callers preserve those sentinel values so the UI can update its detail view
|
||||
/// without an additional round trip.
|
||||
pub async fn get_ttl<C>(con: &mut C, key: &[u8]) -> Result<i64, String>
|
||||
where
|
||||
C: ConnectionLike + Send + Sync + Unpin,
|
||||
{
|
||||
redis::cmd("TTL").arg(key).query_async(con).await.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
fn redis_value_matches_query(value: &RedisValue, query: &str) -> bool {
|
||||
let query = query.trim();
|
||||
if query.is_empty() {
|
||||
|
||||
@@ -137,6 +137,37 @@ pub async fn redis_get_value_in_db_core(
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch only the TTL for a selected key. This avoids repeatedly loading a
|
||||
/// potentially large Redis value when the desktop detail view is polling.
|
||||
pub async fn redis_get_ttl_in_db_core(
|
||||
state: &AppState,
|
||||
connection_id: &str,
|
||||
db: u32,
|
||||
key_raw: &str,
|
||||
) -> Result<i64, String> {
|
||||
ensure_redis_pool(state, connection_id).await?;
|
||||
let connections = state.connections.read().await;
|
||||
let pool = connections.get(connection_id).ok_or("Connection not found")?;
|
||||
match pool {
|
||||
PoolKind::Redis(redis) => {
|
||||
let key = redis_driver::redis_key_raw_to_bytes(key_raw)?;
|
||||
match redis {
|
||||
RedisConnection::Direct(con) => {
|
||||
let mut con = con.lock().await;
|
||||
redis_driver::select_db(&mut *con, db).await?;
|
||||
redis_driver::get_ttl(&mut *con, &key).await
|
||||
}
|
||||
RedisConnection::Cluster(cluster) => {
|
||||
redis_driver::ensure_cluster_db(db)?;
|
||||
let mut con = redis_driver::cluster_key_connection(cluster, &key).await?;
|
||||
redis_driver::get_ttl(&mut con, &key).await
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => Err("Not a Redis connection".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn redis_stream_entries_in_db_core(
|
||||
state: &AppState,
|
||||
connection_id: &str,
|
||||
|
||||
Reference in new issue
Block a user