From 3807f4cf600bee5e692cfc03f0bfc0a4b14862df Mon Sep 17 00:00:00 2001 From: mtvpls Date: Mon, 12 Jan 2026 20:16:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dredis=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E6=B1=82=E7=89=87=E7=9B=B8=E5=85=B3=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/redis-base.db.ts | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/lib/redis-base.db.ts b/src/lib/redis-base.db.ts index b5dc01b..1a43eb6 100644 --- a/src/lib/redis-base.db.ts +++ b/src/lib/redis-base.db.ts @@ -1240,4 +1240,52 @@ export abstract class BaseRedisStorage implements IStorage { this.client.set(this.lastFavoriteCheckKey(userName), timestamp.toString()) ); } + + // ---------- 求片相关 ---------- + private movieRequestsKey() { + return 'movie_requests:all'; + } + + private userMovieRequestsKey(userName: string) { + return `u:${userName}:mr`; + } + + async getAllMovieRequests(): Promise { + const data = await this.withRetry(() => this.client.hGetAll(this.movieRequestsKey())); + if (!data || Object.keys(data).length === 0) return []; + return Object.values(data).map(v => JSON.parse(v) as import('./types').MovieRequest); + } + + async getMovieRequest(requestId: string): Promise { + const val = await this.withRetry(() => this.client.hGet(this.movieRequestsKey(), requestId)); + return val ? (JSON.parse(val) as import('./types').MovieRequest) : null; + } + + async createMovieRequest(request: import('./types').MovieRequest): Promise { + await this.withRetry(() => this.client.hSet(this.movieRequestsKey(), request.id, JSON.stringify(request))); + } + + async updateMovieRequest(requestId: string, updates: Partial): Promise { + const existing = await this.getMovieRequest(requestId); + if (!existing) throw new Error('Movie request not found'); + const updated = { ...existing, ...updates }; + await this.withRetry(() => this.client.hSet(this.movieRequestsKey(), requestId, JSON.stringify(updated))); + } + + async deleteMovieRequest(requestId: string): Promise { + await this.withRetry(() => this.client.hDel(this.movieRequestsKey(), requestId)); + } + + async getUserMovieRequests(userName: string): Promise { + const val = await this.withRetry(() => this.client.sMembers(this.userMovieRequestsKey(userName))); + return val ? ensureStringArray(val) : []; + } + + async addUserMovieRequest(userName: string, requestId: string): Promise { + await this.withRetry(() => this.client.sAdd(this.userMovieRequestsKey(userName), requestId)); + } + + async removeUserMovieRequest(userName: string, requestId: string): Promise { + await this.withRetry(() => this.client.sRem(this.userMovieRequestsKey(userName), requestId)); + } }