diff --git a/src/database/redis.js b/src/database/redis.js index a90a203..20f6a3a 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -31,6 +31,7 @@ class RedisServer { async connect() { if (this.connected) return; + logger.info('Connecting to Redis...'); await this.client.connect(); this.connected = true; logger.info('Connected to Redis'); @@ -61,6 +62,21 @@ class RedisServer { await this.connect(); await this.client.del(key); } + + async getKeysByPattern(pattern) { + await this.connect(); + const keys = []; + let cursor = '0'; + do { + const result = await this.client.scan(cursor, { + MATCH: pattern, + COUNT: 100, + }); + cursor = result.cursor; + keys.push(...result.keys); + } while (cursor !== '0'); + return keys; + } } const redisServer = new RedisServer();