|
|
@@ -49,9 +49,6 @@ export interface TsCacheKeyBuilder {
|
|
|
withCategories(channelId: string | number): string;
|
|
|
};
|
|
|
|
|
|
- /**
|
|
|
- * Category-related cache keys.
|
|
|
- */
|
|
|
category: {
|
|
|
/** Get category by ID. */
|
|
|
byId(categoryId: string | number): string;
|
|
|
@@ -63,43 +60,8 @@ export interface TsCacheKeyBuilder {
|
|
|
withTags(categoryId: string | number): string;
|
|
|
};
|
|
|
|
|
|
- /**
|
|
|
- * Tag-related cache keys.
|
|
|
- *
|
|
|
- * ⚠️ CRITICAL: Distinguish between tag.all() (a global TAG POOL that contains Tag JSON objects)
|
|
|
- * and video.tagList() (which returns video IDs filtered by tag and contains VIDEO IDs only).
|
|
|
- *
|
|
|
- * SEE: libs/common/src/cache/CACHE_SEMANTICS.md
|
|
|
- */
|
|
|
tag: {
|
|
|
- /**
|
|
|
- * Get all tags (global suggestion pool).
|
|
|
- * Redis Type: JSON (Array of Tag objects)
|
|
|
- * Elements: Tag objects (stringified JSON)
|
|
|
- *
|
|
|
- * Format: { id, name, seq, status, createAt, updateAt, channelId, categoryId }
|
|
|
- *
|
|
|
- * ✅ This key contains TAG JSON objects
|
|
|
- * ❌ Not video IDs (that's video.tagList)
|
|
|
- *
|
|
|
- * Example: tsCacheKeys.tag.all()
|
|
|
- * → "box:app:tag:all"
|
|
|
- * → GET and parse as JSON array
|
|
|
- */
|
|
|
all(): string;
|
|
|
-
|
|
|
- /**
|
|
|
- * Get tag metadata (JSON array) for a specific category.
|
|
|
- * Redis Type: STRING (JSON array)
|
|
|
- * Elements: Tag metadata objects with id, name, seq, etc.
|
|
|
- *
|
|
|
- * ✅ This key contains TAG METADATA (entire tag objects)
|
|
|
- * ❌ Not video IDs (that's video.tagList)
|
|
|
- *
|
|
|
- * Example: tsCacheKeys.tag.metadataByCategory('cat-001')
|
|
|
- * → "box:app:tag:list:cat-001"
|
|
|
- * → GET and parse as JSON array
|
|
|
- */
|
|
|
metadataByCategory(categoryId: string | number): string;
|
|
|
};
|
|
|
|
|
|
@@ -111,89 +73,17 @@ export interface TsCacheKeyBuilder {
|
|
|
poolByType(adType: AdType | string): string;
|
|
|
};
|
|
|
|
|
|
- /**
|
|
|
- * Video-related cache keys.
|
|
|
- *
|
|
|
- * ⚠️ CRITICAL: Understand the distinction between "list" and "pool" keys.
|
|
|
- *
|
|
|
- * LIST keys (video.categoryList, video.tagList) map to Redis LISTs that store video IDs only (strings like "64a2b3c4d5e6f7g8h9i0j1k2") in business sequence order and operate via LRANGE/RPUSH to return videos for categories or tags.
|
|
|
- *
|
|
|
- * POOL keys (video.categoryPool, video.tagPool) map to Redis ZSETs whose members are video IDs with timestamp scores sorted from newest to oldest; they rely on ZREVRANGE/ZADD for pagination.
|
|
|
- *
|
|
|
- * SEE: libs/common/src/cache/CACHE_SEMANTICS.md for complete documentation
|
|
|
- */
|
|
|
video: {
|
|
|
- /**
|
|
|
- * Get video detail data.
|
|
|
- * Redis Type: STRING (JSON object)
|
|
|
- */
|
|
|
detail(videoId: string): string;
|
|
|
- /**
|
|
|
- * Get video payload data (minimal metadata) per video.
|
|
|
- * Redis Type: STRING (JSON object)
|
|
|
- */
|
|
|
payload(videoId: string): string;
|
|
|
-
|
|
|
- /**
|
|
|
- * Get video category list by category.
|
|
|
- * Redis Type: LIST
|
|
|
- * Elements: Video IDs ONLY (strings)
|
|
|
- * Order: Business sequence (seq/newest first)
|
|
|
- *
|
|
|
- * Example: tsCacheKeys.video.categoryList('cat-001')
|
|
|
- * → "box:app:video:category:list:cat-001"
|
|
|
- */
|
|
|
categoryList(categoryId: string): string;
|
|
|
-
|
|
|
- /**
|
|
|
- * Get video tag list by category and tag.
|
|
|
- * Redis Type: LIST
|
|
|
- * Elements: Video IDs ONLY (strings, filtered by tag)
|
|
|
- * Order: Same as categoryList
|
|
|
- *
|
|
|
- * ⚠️ NOT to be confused with tag.all() which contains TAG JSON
|
|
|
- *
|
|
|
- * Example: tsCacheKeys.video.tagList('cat-001', 'tag-sports')
|
|
|
- * → "box:app:video:tag:list:cat-001:tag-sports"
|
|
|
- */
|
|
|
tagList(categoryId: string, tagId: string): string;
|
|
|
-
|
|
|
- /**
|
|
|
- * Get videos in a category with sort order (ZSET pool).
|
|
|
- * Redis Type: ZSET
|
|
|
- * Members: Video IDs (strings)
|
|
|
- * Scores: Timestamp (newest first via ZREVRANGE)
|
|
|
- * Use: Pagination with consistent ordering
|
|
|
- *
|
|
|
- * Example: tsCacheKeys.video.categoryPool('ch-1', 'cat-1', 'latest')
|
|
|
- * → "box:app:video:list:category:ch-1:cat-1:latest"
|
|
|
- * → ZREVRANGE to get page results
|
|
|
- */
|
|
|
categoryPool(
|
|
|
channelId: string,
|
|
|
categoryId: string,
|
|
|
sort: VideoSortKey,
|
|
|
): string;
|
|
|
-
|
|
|
- /**
|
|
|
- * Get videos with a specific tag with sort order (ZSET pool).
|
|
|
- * Redis Type: ZSET
|
|
|
- * Members: Video IDs (strings)
|
|
|
- * Scores: Timestamp (newest first via ZREVRANGE)
|
|
|
- * Use: Pagination with consistent ordering
|
|
|
- *
|
|
|
- * Example: tsCacheKeys.video.tagPool('ch-1', 'tag-1', 'latest')
|
|
|
- * → "box:app:video:list:tag:ch-1:tag-1:latest"
|
|
|
- * → ZREVRANGE to get page results
|
|
|
- */
|
|
|
tagPool(channelId: string, tagId: string, sort: VideoSortKey): string;
|
|
|
-
|
|
|
- /**
|
|
|
- * Get home page video section.
|
|
|
- * Redis Type: LIST
|
|
|
- * Elements: Video IDs (strings)
|
|
|
- * Order: Most recent first (limited to N items)
|
|
|
- */
|
|
|
homeSection(channelId: string, section: string): string;
|
|
|
recommended(): string;
|
|
|
latest(): string;
|
|
|
@@ -214,10 +104,6 @@ export interface TsCacheKeyBuilder {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Create a TypeScript-friendly cache key builder.
|
|
|
- * This provides structured access to all cache key generators with proper typing.
|
|
|
- */
|
|
|
export function createTsCacheKeyBuilder(): TsCacheKeyBuilder {
|
|
|
return {
|
|
|
channel: {
|
|
|
@@ -267,8 +153,4 @@ export function createTsCacheKeyBuilder(): TsCacheKeyBuilder {
|
|
|
},
|
|
|
};
|
|
|
}
|
|
|
-
|
|
|
-/**
|
|
|
- * Singleton instance of the TypeScript-friendly cache key builder.
|
|
|
- */
|
|
|
export const tsCacheKeys = createTsCacheKeyBuilder();
|