Skip to content

A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.

C++

feat(redis): add namespace key tree browser (#69)

Tobi2aac3ba3c216
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3e63888..fa5c141 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,11 @@
All notable changes to Gridex are documented in this file. Gridex ships native apps for **macOS** (Swift/AppKit) and **Windows** (C++/WinUI 3). Unless noted otherwise, changes apply to both platforms.
+## [Unreleased]
+
+### Added
+- **Redis namespace key tree (macOS)** — Redis keys can be browsed as a collapsible sidebar tree using a local configurable delimiter (default `:`). Leaf keys open the existing detail view; the flat SCAN-filtered key list remains available.
+
## [0.23.0] - 2026-04-12
### Added
diff --git a/macos/App/State/AppState.swift b/macos/App/State/AppState.swift
index 8a8c57d..5ec3823 100644
--- a/macos/App/State/AppState.swift
+++ b/macos/App/State/AppState.swift
@@ -102,6 +102,11 @@ final class AppState: ObservableObject {
@Published var redisDBSize: Int?
@Published var showFlushDBConfirm = false
@Published var showRedisAddKey = false
+ @Published private(set) var redisKeyBrowserRefreshNonce = 0
+
+ func requestRedisKeyBrowserRefresh() {
+ redisKeyBrowserRefreshNonce &+= 1
+ }
// MARK: - Query Log (global, shared across all tables)
@Published var queryLog: [QueryLogEntry] = []
@@ -334,6 +339,12 @@ final class AppState: ObservableObject {
}
func loadSidebar(config: ConnectionConfig, adapter: any DatabaseAdapter) async {
+ if config.databaseType == .redis {
+ sidebarItems = []
+ requestRedisKeyBrowserRefresh()
+ return
+ }
+
do {
// Run all queries in parallel instead of sequential
async let tablesTask = adapter.listTables(schema: nil)
@@ -498,6 +509,12 @@ final class AppState: ObservableObject {
// MARK: - Redis Tabs
+ func openRedisFlatKeyList() {
+ openTable(name: "Keys", schema: nil)
+ guard let tabID = activeTabId else { return }
+ cachedDataGridState(for: tabID).showFilterBar = true
+ }
+
func openRedisKeyDetail(key: String) {
if let existing = tabs.first(where: { $0.type == .redisKeyDetail && $0.tableName == key }) {
activeTabId = existing.id
@@ -723,6 +740,10 @@ final class AppState: ObservableObject {
func refreshSidebar() {
guard let adapter = activeAdapter, let config = activeConfig else { return }
+ if config.databaseType == .redis {
+ requestRedisKeyBrowserRefresh()
+ return
+ }
Task { await loadSidebar(config: config, adapter: adapter) }
}
diff --git a/macos/Data/Adapters/Redis/RedisAdapter.swift b/macos/Data/Adapters/Redis/RedisAdapter.swift
index e9200b2..5b55274 100644
--- a/macos/Data/Adapters/Redis/RedisAdapter.swift
+++ b/macos/Data/Adapters/Redis/RedisAdapter.swift
@@ -368,6 +368,42 @@ final class RedisAdapter: DatabaseAdapter, @unchecked Sendable {
// MARK: - Pagination (SCAN-based)
+ func scanKeyNames(
+ matching pattern: String = "*",
+ maximumCount: Int = 10_000
+ ) async throws -> RedisKeyScanResult {
+ var cursor = 0
+ var accumulator = RedisKeyScanAccumulator(maximumCount: maximumCount)
+
+ repeat {
+ guard connection?.isConnected == true else {
+ throw GridexError.queryExecutionFailed("Connection lost during SCAN")
+ }
+
+ let response: RESPValue
+ do {
+ response = try await sendCommand(
+ "SCAN",
+ args: [String(cursor), "MATCH", pattern, "COUNT", "500"]
+ )
+ } catch {
+ guard connection?.isConnected == true else {
+ throw GridexError.queryExecutionFailed("Connection lost during SCAN")
+ }
+ throw error
+ }
+
+ guard case .array(let parts) = response, parts.count == 2 else { break }
+ cursor = Int(respToRowValue(parts[0]).stringValue ?? "0") ?? 0
+
+ if case .array(let keys) = parts[1] {
+ accumulator.append(keys.compactMap { respToRowValue($0).stringValue })
+ }
+ } while cursor != 0 && !accumulator.isFull
+
+ return accumulator.result(hasMoreCursor: cursor != 0)
+ }
+
func fetchRows(
table: String,
schema: String?,
diff --git a/macos/Presentation/Views/Redis/RedisKeyBrowserView.swift b/macos/Presentation/Views/Redis/RedisKeyBrowserView.swift
new file mode 100644
index 0000000..643df00
--- /dev/null
+++ b/macos/Presentation/Views/Redis/RedisKeyBrowserView.swift
@@ -0,0 +1,329 @@
+// RedisKeyBrowserView.swift
+// Gridex
+//
+// Redis-specific sidebar browser backed by a names-only SCAN.
+
+import SwiftUI
+
+enum RedisKeyBrowserBehavior {
+ static func effectiveDelimiter(for delimiter: String) -> String {
+ delimiter.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
+ ? ":"
+ : delimiter
+ }
+
+ static func shouldPublish(
+ capturedNonce: Int,
+ currentNonce: Int,
+ isCancelled: Bool
+ ) -> Bool {
+ !isCancelled && capturedNonce == currentNonce
+ }
+}
+
+enum RedisKeyBrowserMode: String, CaseIterable, Identifiable {
+ case tree, flat
+
+ var id: String { rawValue }
+}
+
+struct RedisKeyBrowserView: View {
+ @EnvironmentObject private var appState: AppState
+ @AppStorage("redis.keyBrowser.delimiter") private var delimiter = ":"
+ @State private var mode: RedisKeyBrowserMode = .tree
+ @State private var lastSuccessfulResult = RedisKeyScanResult(keys: [], isTruncated: false)
+ @State private var hasSuccessfulResult = false
+ @State private var isLoading = false
+ @State private var errorMessage: String?
+
+ private var effectiveDelimiter: String {
+ RedisKeyBrowserBehavior.effectiveDelimiter(for: delimiter)
+ }
+
+ private var namespaceNodes: [RedisKeyNamespaceNode] {
+ RedisKeyNamespaceTree.build(
+ keys: lastSuccessfulResult.keys,
+ delimiter: effectiveDelimiter
+ )
+ }
+
+ var body: some View {
+ VStack(spacing: 0) {
+ toolbar
+ Divider()
+
+ if mode == .flat {
+ flatContent
+ } else {
+ treeContent
+ }
+ }
+ .onChange(of: mode) { _, newMode in
+ if newMode == .flat {
+ appState.openRedisFlatKeyList()
+ }
+ }
+ .onReceive(NotificationCenter.default.publisher(for: .reloadData)) { _ in
+ appState.requestRedisKeyBrowserRefresh()
+ }
+ .task(id: appState.redisKeyBrowserRefreshNonce) {
+ let capturedNonce = appState.redisKeyBrowserRefreshNonce
+ await scanKeys(capturedNonce: capturedNonce)
+ }
+ }
+
+ private var toolbar: some View {
+ VStack(alignment: .leading, spacing: 5) {
+ HStack(spacing: 6) {
+ Picker("Mode", selection: $mode) {
+ ForEach(RedisKeyBrowserMode.allCases) { mode in
+ Text(mode.rawValue.capitalized).tag(mode)
+ }
+ }
+ .labelsHidden()
+ .pickerStyle(.segmented)
+ .frame(width: 118)
+
+ Spacer()
+
+ Button {
+ appState.requestRedisKeyBrowserRefresh()
+ } label: {
+ HStack(spacing: 4) {
+ if isLoading {
+ ProgressView()
+ .controlSize(.small)
+ .frame(width: 12, height: 12)
+ } else {
+ Image(systemName: "arrow.clockwise")
+ .font(.system(size: 10))
+ .frame(width: 12, height: 12)
+ }
+ Text("Refresh")
+ .font(.system(size: 11))
+ }
+ }
+ .buttonStyle(.plain)
+ .help("Refresh Redis keys")
+ }
+
+ Text("Delimiter: \(effectiveDelimiter)")
+ .font(.system(size: 10, design: .monospaced))
+ .foregroundStyle(.secondary)
+ .lineLimit(1)
+ }
+ .padding(.horizontal, 8)
+ .padding(.vertical, 6)
+ }
+
+ @ViewBuilder
+ private var treeContent: some View {
+ if !hasSuccessfulResult {
+ if let errorMessage {
+ errorView(errorMessage)
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ } else {
+ ProgressView()
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ }
+ } else {
+ VStack(spacing: 0) {
+ if let errorMessage {
+ errorBanner(errorMessage)
+ Divider()
+ }
+
+ if lastSuccessfulResult.keys.isEmpty {
+ Text("No keys found")
+ .font(.system(size: 12))
+ .foregroundStyle(.secondary)
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ } else {
+ ScrollView {
+ LazyVStack(alignment: .leading, spacing: 1) {
+ ForEach(namespaceNodes) { node in
+ RedisKeyNamespaceNodeView(node: node) { key in
+ appState.openRedisKeyDetail(key: key)
+ }
+ }
+ }
+ .padding(.horizontal, 7)
+ .padding(.vertical, 5)
+ }
+ }
+
+ if lastSuccessfulResult.isTruncated {
+ Divider()
+ Text("Showing the first 10,000 keys. Use Flat mode to filter with SCAN.")
+ .font(.system(size: 10))
+ .foregroundStyle(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ .padding(8)
+ }
+ }
+ }
+ }
+
+ private var flatContent: some View {
+ VStack(spacing: 8) {
+ Spacer()
+ Image(systemName: "list.bullet.rectangle")
+ .font(.system(size: 24))
+ .foregroundStyle(.secondary)
+ Text("The existing Keys tab is open.")
+ .font(.system(size: 12, weight: .medium))
+ Text("Use its SCAN filter to narrow the flat key list.")
+ .font(.system(size: 11))
+ .foregroundStyle(.secondary)
+ .multilineTextAlignment(.center)
+ Button("Show Tree") { mode = .tree }
+ .controlSize(.small)
+ Spacer()
+ }
+ .padding()
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ }
+
+ private func errorView(_ message: String) -> some View {
+ VStack(spacing: 8) {
+ Image(systemName: "exclamationmark.triangle")
+ .foregroundStyle(.orange)
+ Text(message)
+ .font(.system(size: 11))
+ .foregroundStyle(.secondary)
+ .multilineTextAlignment(.center)
+ .textSelection(.enabled)
+ Button("Retry") { appState.requestRedisKeyBrowserRefresh() }
+ .controlSize(.small)
+ }
+ .padding()
+ }
+
+ private func errorBanner(_ message: String) -> some View {
+ HStack(spacing: 6) {
+ Image(systemName: "exclamationmark.triangle.fill")
+ .foregroundStyle(.orange)
+ Text(message)
+ .font(.system(size: 10))
+ .foregroundStyle(.secondary)
+ .lineLimit(2)
+ Spacer()
+ Button("Retry") { appState.requestRedisKeyBrowserRefresh() }
+ .controlSize(.mini)
+ }
+ .padding(.horizontal, 8)
+ .padding(.vertical, 5)
+ }
+
+ @MainActor
+ private func scanKeys(capturedNonce: Int) async {
+ isLoading = true
+ errorMessage = nil
+
+ guard let redis = appState.activeAdapter as? RedisAdapter else {
+ publishError("Not connected to Redis", capturedNonce: capturedNonce)
+ return
+ }
+
+ do {
+ let result = try await redis.scanKeyNames()
+ guard RedisKeyBrowserBehavior.shouldPublish(
+ capturedNonce: capturedNonce,
+ currentNonce: appState.redisKeyBrowserRefreshNonce,
+ isCancelled: Task.isCancelled
+ ) else { return }
+
+ lastSuccessfulResult = result
+ hasSuccessfulResult = true
+ errorMessage = nil
+ isLoading = false
+ } catch {
+ publishError(error.localizedDescription, capturedNonce: capturedNonce)
+ }
+ }
+
+ @MainActor
+ private func publishError(_ message: String, capturedNonce: Int) {
+ guard RedisKeyBrowserBehavior.shouldPublish(
+ capturedNonce: capturedNonce,
+ currentNonce: appState.redisKeyBrowserRefreshNonce,
+ isCancelled: Task.isCancelled
+ ) else { return }
+
+ errorMessage = message
+ isLoading = false
+ }
+}
+
+private struct RedisKeyNamespaceNodeView: View {
+ let node: RedisKeyNamespaceNode
+ let openKey: (String) -> Void
+
+ var body: some View {
+ if node.children.isEmpty {
+ leafRow
+ } else {
+ DisclosureGroup {
+ ForEach(node.children) { child in
+ RedisKeyNamespaceNodeView(node: child, openKey: openKey)
+ }
+ } label: {
+ namespaceRow
+ }
+ }
+ }
+
+ private var namespaceRow: some View {
+ HStack(spacing: 5) {
+ Image(systemName: "folder")
+ .font(.system(size: 11))
+ .foregroundStyle(.secondary)
+ Text(RedisKeyNamespaceTree.displayLabel(for: node.segment))
+ .font(.system(size: 12, design: .monospaced))
+ .lineLimit(1)
+ Spacer(minLength: 4)
+ Text("\(node.descendantKeyCount)")
+ .font(.system(size: 9, design: .monospaced))
+ .foregroundStyle(.tertiary)
+ if let concreteKey = node.concreteKey {
+ Button {
+ openKey(concreteKey)
+ } label: {
+ Image(systemName: "key.fill")
+ .font(.system(size: 9))
+ .frame(width: 18, height: 18)
+ }
+ .buttonStyle(.plain)
+ .help("Open key \(concreteKey)")
+ }
+ }
+ .padding(.vertical, 2)
+ }
+
+ @ViewBuilder
+ private var leafRow: some View {
+ if let concreteKey = node.concreteKey {
+ Button {
+ openKey(concreteKey)
+ } label: {
+ HStack(spacing: 5) {
+ Image(systemName: "key")
+ .font(.system(size: 10))
+ .foregroundStyle(.secondary)
+ Text(RedisKeyNamespaceTree.displayLabel(for: node.segment))
+ .font(.system(size: 12, design: .monospaced))
+ .lineLimit(1)
+ Spacer()
+ }
+ .padding(.vertical, 3)
+ .contentShape(Rectangle())
+ }
+ .buttonStyle(.plain)
+ .help("Open key \(concreteKey)")
+ } else {
+ Text(RedisKeyNamespaceTree.displayLabel(for: node.segment))
+ .font(.system(size: 12, design: .monospaced))
+ .padding(.vertical, 3)
+ }
+ }
+}
diff --git a/macos/Presentation/Views/Sidebar/SidebarView.swift b/macos/Presentation/Views/Sidebar/SidebarView.swift
index d6ee079..1ff2383 100644
--- a/macos/Presentation/Views/Sidebar/SidebarView.swift
+++ b/macos/Presentation/Views/Sidebar/SidebarView.swift
@@ -87,19 +87,24 @@ struct SidebarView: View {
// MARK: - Items tab
+ @ViewBuilder
private var itemsTab: some View {
VStack(spacing: 0) {
- searchBar
- Divider()
+ if appState.activeConfig?.databaseType == .redis {
+ RedisKeyBrowserView()
+ } else {
+ searchBar
+ Divider()
- List {
- ForEach(filteredItems, id: \.id) { item in
- SidebarItemRow(item: item, searchText: searchText)
+ List {
+ ForEach(filteredItems, id: \.id) { item in
+ SidebarItemRow(item: item, searchText: searchText)
+ }
}
+ .listStyle(.plain)
+ .scrollContentBackground(.hidden)
+ .background(Color(NSColor.windowBackgroundColor))
}
- .listStyle(.plain)
- .scrollContentBackground(.hidden)
- .background(Color(NSColor.windowBackgroundColor))
Divider()
bottomBar
diff --git a/macos/Presentation/Windows/Settings/SettingsView.swift b/macos/Presentation/Windows/Settings/SettingsView.swift
index 32bcd91..157ff1c 100644
--- a/macos/Presentation/Windows/Settings/SettingsView.swift
+++ b/macos/Presentation/Windows/Settings/SettingsView.swift
@@ -34,6 +34,7 @@ struct GeneralSettingsView: View {
@AppStorage("general.refreshInterval") private var refreshInterval = 300 // seconds
@AppStorage("general.showQueryLog") private var showQueryLog = false
@AppStorage("mcp.hideStatusBarIcon") private var hideStatusBarIcon = false
+ @AppStorage("redis.keyBrowser.delimiter") private var redisKeyBrowserDelimiter = ":"
var body: some View {
Form {
@@ -59,6 +60,14 @@ struct GeneralSettingsView: View {
}
}
+ Section("Redis") {
+ TextField("Key namespace delimiter", text: $redisKeyBrowserDelimiter)
+ .onSubmit(normalizeRedisKeyBrowserDelimiter)
+ Text("Keys are grouped by this delimiter in the sidebar.")
+ .font(.system(size: 11))
+ .foregroundStyle(.secondary)
+ }
+
Section("Query") {
Toggle("Show query log panel by default", isOn: $showQueryLog)
}
@@ -74,6 +83,13 @@ struct GeneralSettingsView: View {
MCPStatusBarController.shared.refresh()
}
}
+ .onDisappear(perform: normalizeRedisKeyBrowserDelimiter)
+ }
+
+ private func normalizeRedisKeyBrowserDelimiter() {
+ redisKeyBrowserDelimiter = RedisKeyBrowserBehavior.effectiveDelimiter(
+ for: redisKeyBrowserDelimiter
+ )
}
}