Redis Explorer
Relevant source files
The following files were used as context for generating this wiki page:
The Redis Explorer is a specialized module within KamehaDB designed for interacting with Redis databases. It provides a comprehensive suite of tools for key management, real-time metrics monitoring, and raw command execution. Unlike the standard SQL interfaces in the project, the Redis Explorer utilizes a dedicated adapter and route system to handle the unique data structures and key-value paradigms of Redis.
Sources: AGENTS.md, README.md, PLAN.md
System Architecture and Data Flow
The Redis Explorer architecture follows the project's standard split between the Tauri desktop frontend and the Node.js sidecar backend. The frontend provides interactive UI components for browsing and querying, while the sidecar manages the actual ioredis client connections and data normalization.
Communication Flow
The following diagram illustrates the sequence of a key lookup request from the UI to the database:
Key Management and Browsing
The RedisExplorer component provides a sidebar for scanning and filtering keys. It supports multiple Redis data types and provides type-specific visualizations.
Supported Data Types and Visualization
The system identifies and formats data based on the Redis type returned by the TYPE command:
| Redis Type | UI Icon | Display Logic |
|---|---|---|
string | Type | Displays as a mono-spaced text block. |
hash | Hash | Renders as a key-value list with highlighted field names. |
list | List | Shows an indexed list of elements (limited to first 20). |
set | Box | Displays as a list of unique members. |
zset | Box | Shows members with associated scores. |
Sources: apps/desktop/src/components/redis-explorer.tsx:8-21, apps/sidecar/src/adapters/redis.ts:31-52
Key Scanning Logic
Key discovery is performed using the SCAN command rather than KEYS to prevent blocking the Redis server. The scanKeys function in the sidecar adapter handles cursor management and returns a paginated list of keys along with their types and TTLs.
Sources: apps/sidecar/src/adapters/redis.ts:74-96
Database Analytics and Metrics
Redis performance and health are monitored through the RedisDatabaseStats and RedisStats components. These components parse the output of the Redis INFO command to provide structured metrics.
Key Performance Indicators
- Memory Usage: Tracks
used_memory,used_memory_peak, andmaxmemory. - Clients: Monitors
connected_clientsandblocked_clients. - Keyspace: Calculates total keys, expiring keys, and average TTL for the selected logical database.
- Hit Rate: Computed via
keyspace_hitsandkeyspace_misses.
Raw Command Interface
The RedisQuery component implements a terminal-like environment for executing arbitrary Redis commands.
Features
- Monaco Editor Integration: Provides a dedicated "redis" language mode with syntax highlighting for common keywords like
GET,SET,HGETALL, etc. - Command Execution: Commands are parsed on the backend and executed via the
redis.callmethod. - Result Formatting: Displays execution duration in milliseconds and the raw result from the server.
Sources: apps/desktop/src/components/redis-query.tsx:18-206, apps/sidecar/src/adapters/redis.ts:172-182
API Reference
The sidecar exposes specific endpoints for Redis operations:
| Endpoint | Method | Payload | Description |
|---|---|---|---|
/redis/:id/test | GET | N/A | Tests connection and returns server version. |
/redis/:id/keys | POST | { pattern, count, cursor } | Scans keys matching a pattern. |
/redis/:id/key | POST | { key } | Retrieves type, value, and TTL for a key. |
/redis/:id/command | POST | { command } | Executes a raw Redis command string. |
/redis/:id/stats | GET | N/A | Returns cached database performance metrics. |
Sources: apps/sidecar/src/routes/redis.ts:28-144
Summary
The Redis Explorer serves as a specialized toolset within KamehaDB for managing non-relational key-value data. By combining safety-first key scanning, detailed memory and performance analytics, and a powerful raw command editor, it provides a comprehensive interface for Redis administration alongside traditional SQL support.