fix(redis): fill expanded group subtree via targeted scan

Closes #7162
This commit is contained in:
t8y2 committed 2026-08-26 17:14:12 +08:00
1 parent 83a6ad005b
commit 4b4b4ac2dd
4 files changed
+173 -3

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
import { describe, expect, it } from "vitest";
import { redisGroupSubtreePattern } from "@/lib/redis/redisKeyPattern";
describe("redisGroupSubtreePattern", () => {
it("builds a prefix pattern for single and nested groups", () => {
expect(redisGroupSubtreePattern(["grp"])).toBe("grp:*");
expect(redisGroupSubtreePattern(["grp", "sub"])).toBe("grp:sub:*");
});
it("supports custom separators and preserves empty segments", () => {
expect(redisGroupSubtreePattern(["a", "b"], "/")).toBe("a/b/*");
expect(redisGroupSubtreePattern(["a", "", "c"])).toBe("a::c:*");
});
it("escapes glob metacharacters in every segment", () => {
expect(redisGroupSubtreePattern(["a*b"])).toBe("a\\*b:*");
expect(redisGroupSubtreePattern(["order?]", "x[y"])).toBe("order\\?\\]:x\\[y:*");
expect(redisGroupSubtreePattern(["back\\slash"])).toBe("back\\\\slash:*");
});
});
@@ -11,6 +11,16 @@ export function redisKeySearchPattern(value: string, fuzzy: boolean): string {
return fuzzy ? `*${escapeRedisGlobText(pattern, fuzzy)}*` : pattern;
}
/**
* SCAN MATCH pattern covering exactly the subtree of a tree group: every
* segment is glob-escaped so keys containing `*`/`?`/`[`/`]` match literally,
* and the trailing `*` only widens to the group's descendants.
*/
export function redisGroupSubtreePattern(pathSegments: readonly string[], separator = ":"): string {
const prefix = pathSegments.map((segment) => escapeRedisGlobText(segment)).join(separator);
return `${prefix}${separator}*`;
}
// Redis scan page size (COUNT parameter per SCAN round-trip) — shared defaults
// and validation bounds used by the connection form and key browser.
export const REDIS_SCAN_PAGE_SIZE_DEFAULT = 1000;