From 4fbd9dcfbfd93792576eca411b94baafa1387097 Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Wed, 1 Nov 2023 14:47:36 +0100 Subject: [PATCH] upd: make hashtagservice compatible with redis 6.3 --- packages/backend/src/core/HashtagService.ts | 26 ++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/core/HashtagService.ts b/packages/backend/src/core/HashtagService.ts index d37899990..d50b78183 100644 --- a/packages/backend/src/core/HashtagService.ts +++ b/packages/backend/src/core/HashtagService.ts @@ -176,18 +176,28 @@ export class HashtagService { // チャート用 redisPipeline.pfadd(`hashtagUsers:${hashtag}:${window}`, userId); - redisPipeline.expire(`hashtagUsers:${hashtag}:${window}`, - 60 * 60 * 24 * 3, // 3日間 - 'NX', // "NX -- Set expiry only when the key has no expiry" = 有効期限がないときだけ設定 - ); + + const TTLwindow = await this.redisClient.ttl(`hashtagUsers:${hashtag}:${window}`); + + if (TTLwindow === -1) { + redisPipeline.expire(`hashtagUsers:${hashtag}:${window}`, + 60 * 60 * 24 * 3, // 3日間 + //'NX', // "NX -- Set expiry only when the key has no expiry" = 有効期限がないときだけ設定 + ); + } // ユニークカウント用 // TODO: Bloom Filter を使うようにしても良さそう redisPipeline.sadd(`hashtagUsers:${hashtag}`, userId); - redisPipeline.expire(`hashtagUsers:${hashtag}`, - 60 * 60, // 1時間 - 'NX', // "NX -- Set expiry only when the key has no expiry" = 有効期限がないときだけ設定 - ); + + const TTL = await this.redisClient.ttl(`hashtagUsers:${hashtag}`); + + if (TTL === -1) { + redisPipeline.expire(`hashtagUsers:${hashtag}`, + 60 * 60, // 1時間 + //'NX', // "NX -- Set expiry only when the key has no expiry" = 有効期限がないときだけ設定 + ); + } redisPipeline.exec(); }