import { KeyValueStore } from '../types'; /** * Redis store implementation * Requires ioredis package */ export class RedisStore implements KeyValueStore { constructor(private redis: any) {} // ioredis instance async get(key: string): Promise { return await this.redis.get(key); } async set(key: string, value: string, ttl?: number): Promise { if (ttl) { await this.redis.setex(key, ttl, value); } else { await this.redis.set(key, value); } } async delete(key: string): Promise { await this.redis.del(key); } async scan(pattern: string): Promise { const keys: string[] = []; let cursor = '0'; do { const [newCursor, matches] = await this.redis.scan( cursor, 'MATCH', pattern, 'COUNT', 100 ); cursor = newCursor; keys.push(...matches); } while (cursor !== '0'); return keys; } } /** * Create Redis store from connection URL */ export function createRedisStore(redis: any): KeyValueStore { return new RedisStore(redis); }