4 files changed
+173
-3
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user