Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(redis): format INFO output as plain text in cluster mode

dalew0830e03f89a8
diff --git a/crates/dbx-core/src/db/redis_driver.rs b/crates/dbx-core/src/db/redis_driver.rs
index d42abba2a0..cd887fe107 100644
--- a/crates/dbx-core/src/db/redis_driver.rs
+++ b/crates/dbx-core/src/db/redis_driver.rs
@@ -981,6 +981,15 @@ where
redis::cmd("FLUSHDB").query_async::<()>(con).await.map_err(|e| e.to_string())
}
+/// Extract a string reference from a `RedisRawValue` if it is a BulkString or SimpleString.
+fn redis_raw_value_as_str(v: &RedisRawValue) -> Option<&str> {
+ match v {
+ RedisRawValue::BulkString(bytes) => std::str::from_utf8(bytes).ok(),
+ RedisRawValue::SimpleString(s) => Some(s.as_str()),
+ _ => None,
+ }
+}
+
pub async fn execute_command<C>(
con: &mut C,
command_text: &str,
@@ -1002,6 +1011,34 @@ where
}
let raw: RedisRawValue = cmd.query_async(con).await.map_err(|e| e.to_string())?;
+ // Special handling for INFO command in cluster mode.
+ // redis-rs ClusterConnection routes INFO to all primaries and
+ // aggregates the results as a Map(node_addr → full_info_text).
+ // We detect this pattern and format it as human-readable plain text
+ // instead of converting to a JSON array of {key, value} objects.
+ if command == "INFO" {
+ if let RedisRawValue::Map(entries) = &raw {
+ // Cluster-aggregated INFO has multi-line values starting with "# Server".
+ // This distinguishes it from a RESP3 standalone INFO map where values
+ // are single field values (e.g. "redis_version", "os").
+ let is_cluster_aggregation =
+ entries.iter().any(|(_, v)| redis_raw_value_as_str(v).is_some_and(|s| s.starts_with("# Server")));
+
+ if is_cluster_aggregation {
+ let mut parts: Vec<String> = Vec::with_capacity(entries.len());
+ for (key, value) in entries {
+ let addr = redis_raw_value_as_str(key);
+ let info = redis_raw_value_as_str(value);
+ if let (Some(addr), Some(info)) = (addr, info) {
+ parts.push(format!("{addr}\n{info}"));
+ }
+ }
+ let text = parts.join("\n\n");
+ return Ok(RedisCommandResult { command, safety, value: serde_json::Value::String(text) });
+ }
+ }
+ }
+
Ok(RedisCommandResult { command, safety, value: redis_command_raw_to_json(raw) })
}