feat(redis): add configurable key namespace separator

This commit is contained in:
t8y2 committed 2026-06-10 17:46:48 +08:00
1 parent 14d11a9933
commit d353d4673f
20 files changed
+64 -20

No files matched your search

@@ -119,6 +119,7 @@ const defaultForm = (): ConnectionForm => ({
redis_sentinel_password: "",
redis_sentinel_tls: false,
redis_cluster_nodes: "",
redis_key_separator: ":",
etcd_endpoints: "",
read_only: false,
visible_databases: undefined,
@@ -545,6 +546,7 @@ watch(
redis_sentinel_password: config.redis_sentinel_password || "",
redis_sentinel_tls: config.redis_sentinel_tls || false,
redis_cluster_nodes: config.redis_cluster_nodes || "",
redis_key_separator: config.redis_key_separator || ":",
etcd_endpoints: config.etcd_endpoints || "",
read_only: config.read_only || false,
visible_databases: config.visible_databases,
@@ -1057,6 +1059,7 @@ function connectionConfigForSubmit(id: string): ConnectionConfig {
config.redis_sentinel_password = undefined;
config.redis_sentinel_tls = undefined;
config.redis_cluster_nodes = undefined;
config.redis_key_separator = undefined;
} else if (config.redis_connection_mode === "sentinel") {
config.redis_sentinel_master = config.redis_sentinel_master?.trim() || "";
config.redis_sentinel_nodes = normalizeRedisSentinelNodes(config.redis_sentinel_nodes || "");
@@ -1088,6 +1091,9 @@ function connectionConfigForSubmit(id: string): ConnectionConfig {
config.redis_sentinel_tls = undefined;
config.redis_cluster_nodes = undefined;
}
if (config.db_type === "redis") {
config.redis_key_separator = config.redis_key_separator?.trim() || ":";
}
if (config.db_type === "etcd") {
config.etcd_endpoints = normalizeEndpointLines(config.etcd_endpoints || "");
const firstEndpoint = firstEtcdEndpoint(config.etcd_endpoints);
@@ -2376,6 +2382,10 @@ function openExternalUrl(url: string) {
<Label class="text-right">{{ t("connection.password") }}</Label>
<Input v-model="form.password" type="password" class="col-span-3" :placeholder="t('connection.databasePlaceholder')" />
</div>
<div class="grid grid-cols-4 items-center gap-4">
<Label class="text-right text-xs">{{ t("connection.redisKeySeparator") }}</Label>
<Input v-model="form.redis_key_separator" class="col-span-3 h-8 text-xs" placeholder=":" />
</div>
</template>
<!-- etcd: endpoints, user, password, TLS -->
@@ -104,6 +104,7 @@ const effectivePattern = computed(() => (searchMode.value === "key" ? redisKeySe
const isSearchMode = computed(() => (searchMode.value === "key" ? effectivePattern.value !== "*" : valueQuery.value !== ""));
const searchPlaceholder = computed(() => (searchMode.value === "key" ? (fuzzyKeySearch.value ? t("redis.fuzzyPattern") : t("redis.pattern")) : t("redis.valueSearchPlaceholder")));
const loadingEmptyText = computed(() => (searchMode.value === "value" && valueQuery.value ? t("redis.searchingValues") : t("redis.loadingKeys")));
const redisKeySeparator = computed(() => connectionStore.getConfig(props.connectionId)?.redis_key_separator || ":");
const lastTotalKeys = ref(0);
const fetchAllProgressText = computed(() => {
if (!isFetchingAll.value) return "";
@@ -151,7 +152,7 @@ function countLeaves(node: RedisKeyTreeNode): number {
}
function rebuildTree(expandAll = false) {
const nextTree = buildRedisKeyTree(flatKeys.value, props.db);
const nextTree = buildRedisKeyTree(flatKeys.value, props.db, redisKeySeparator.value);
treeKeys.value = nextTree;
const nextExpanded = new Set<string>();
@@ -172,7 +173,7 @@ function rebuildTree(expandAll = false) {
function mergeTree(newKeys: RedisKeyInfo[]) {
if (newKeys.length === 0) return;
treeKeys.value = mergeKeysIntoRedisKeyTree(treeKeys.value, newKeys, props.db);
treeKeys.value = mergeKeysIntoRedisKeyTree(treeKeys.value, newKeys, props.db, redisKeySeparator.value);
const availableExpanded = collectExpandedGroupIds(treeKeys.value);
const nextExpanded = new Set<string>();
+1
View File
@@ -222,6 +222,7 @@
redisSentinelPassword: "Sentinel Password",
redisSentinelTls: "Sentinel TLS",
redisSentinelTlsHint: "Use TLS when connecting to Sentinel nodes",
redisKeySeparator: "Key Namespace Separator",
etcdEndpoints: "Endpoints",
etcdEndpointsHint: "One endpoint per line. Leave blank to use the host and port above.",
etcdCaCertPlaceholder: "/path/to/ca.crt",
+1
View File
@@ -215,6 +215,7 @@
redisSentinelPassword: "Contraseña Sentinel",
redisSentinelTls: "TLS Sentinel",
redisSentinelTlsHint: "Usar TLS al conectar con nodos Sentinel",
redisKeySeparator: "Separador de espacio de nombres de clave",
searchDatabasePlaceholder: "Buscar tipos de bases de datos",
iconView: "Vista de íconos",
listView: "Vista de lista",
+1
View File
@@ -220,6 +220,7 @@
redisSentinelPassword: "Password Sentinel",
redisSentinelTls: "TLS Sentinel",
redisSentinelTlsHint: "Usa TLS quando ti connetti ai nodi Sentinel",
redisKeySeparator: "Separatore namespace chiavi",
searchDatabasePlaceholder: "Cerca tipi di database",
iconView: "Vista icone",
listView: "Vista elenco",
+1
View File
@@ -220,6 +220,7 @@
redisSentinelPassword: "Senha do Sentinel",
redisSentinelTls: "TLS do Sentinel",
redisSentinelTlsHint: "Usar TLS ao conectar aos nós Sentinel",
redisKeySeparator: "Separador de namespace de chave",
searchDatabasePlaceholder: "Pesquisar tipos de banco de dados",
iconView: "Visualização em ícones",
listView: "Visualização em lista",
+1
View File
@@ -223,6 +223,7 @@
redisSentinelPassword: "哨兵密码",
redisSentinelTls: "哨兵 TLS",
redisSentinelTlsHint: "连接 Sentinel 节点时使用 TLS",
redisKeySeparator: "键名命名空间分隔符",
etcdEndpoints: "Endpoints",
etcdEndpointsHint: "每行一个 endpoint。留空时使用上面的 host 和端口。",
etcdCaCertPlaceholder: "/path/to/ca.crt",
+1
View File
@@ -220,6 +220,7 @@
redisSentinelPassword: "Sentinel 密碼",
redisSentinelTls: "Sentinel TLS",
redisSentinelTlsHint: "連線 Sentinel 節點時使用 TLS",
redisKeySeparator: "鍵名命名空間分隔符",
searchDatabasePlaceholder: "搜尋資料庫類型",
iconView: "圖示檢視",
listView: "清單檢視",
+7 -7
View File
@@ -53,19 +53,19 @@ function sortRedisTreeNodes(nodes: RedisKeyTreeNode[]): RedisKeyTreeNode[] {
);
}
export function buildRedisKeyTree(keys: RedisKeyInfo[], db: number): RedisKeyTreeNode[] {
export function buildRedisKeyTree(keys: RedisKeyInfo[], db: number, separator = ":"): RedisKeyTreeNode[] {
const root: RedisKeyTreeNode[] = [];
const groupMap = new Map<string, RedisKeyTreeGroupNode>();
for (const key of keys) {
insertKeyIntoTree(root, groupMap, key, db);
insertKeyIntoTree(root, groupMap, key, db, separator);
}
return sortRedisTreeNodes(root);
}
function insertKeyIntoTree(root: RedisKeyTreeNode[], groupMap: Map<string, RedisKeyTreeGroupNode>, key: RedisKeyInfo, db: number): void {
const pathSegments = key.key_display.split(":");
function insertKeyIntoTree(root: RedisKeyTreeNode[], groupMap: Map<string, RedisKeyTreeGroupNode>, key: RedisKeyInfo, db: number, separator: string): void {
const pathSegments = key.key_display.split(separator);
if (pathSegments.length === 1) {
root.push({
kind: "leaf",
@@ -134,8 +134,8 @@ function rebuildGroupMap(tree: RedisKeyTreeNode[]): Map<string, RedisKeyTreeGrou
return groupMap;
}
export function mergeKeysIntoRedisKeyTree(existingTree: RedisKeyTreeNode[], newKeys: RedisKeyInfo[], db: number): RedisKeyTreeNode[] {
if (existingTree.length === 0) return buildRedisKeyTree(newKeys, db);
export function mergeKeysIntoRedisKeyTree(existingTree: RedisKeyTreeNode[], newKeys: RedisKeyInfo[], db: number, separator = ":"): RedisKeyTreeNode[] {
if (existingTree.length === 0) return buildRedisKeyTree(newKeys, db, separator);
const groupMap = rebuildGroupMap(existingTree);
const existingKeyIds = new Set<string>();
@@ -152,7 +152,7 @@ export function mergeKeysIntoRedisKeyTree(existingTree: RedisKeyTreeNode[], newK
for (const key of newKeys) {
if (existingKeyIds.has(key.key_raw)) continue;
insertKeyIntoTree(existingTree, groupMap, key, db);
insertKeyIntoTree(existingTree, groupMap, key, db, separator);
}
return sortRedisTreeNodes(existingTree);