diene reports

← coverage tree

src/adapters/redis-kv-store.ts

9b70284 · int · 85.7% (18/21 lines) · open on GitHub

163import { Redis } from 'ioredis';
2import type { IKeyValueStore, RedisConnection } from './kv-store';
3
4export class RedisKeyValueStore implements IKeyValueStore {
51 private readonly client: Redis;
6
747 constructor(connection: RedisConnection) {
862 this.client = new Redis({
956 host: connection.host,
1056 port: connection.port,
1160 maxRetriesPerRequest: 3,
1242 lazyConnect: true,
1314 });
140 this.client.on('error', (error: Error) => {
150 if ((error as NodeJS.ErrnoException).code !== 'ECONNREFUSED') {
160 console.error(`[redis-kv-store] unexpected connection error: ${error.message}`);
176 }
1817 });
19 }
20
2139 async set(key: string, value: string): Promise<void> {
2282 await this.client.set(key, value);
23 }
24
2526 async get(key: string): Promise<string | null> {
2666 return this.client.get(key);
27 }
28
2921 async close(): Promise<void> {
3058 await this.client.quit();
31 }
322}