replaced node-redis with ioredis for now

This commit is contained in:
rykuno 2024-09-02 10:13:13 -05:00
parent b7a081a941
commit 80ba1c9861
3 changed files with 8 additions and 40 deletions

View file

@ -1,7 +0,0 @@
import { Schema } from 'redis-om'
export const loginRequestSchema = new Schema('album', {
id: { type: 'string' },
hashedToken: { type: 'string' },
email: { type: 'string' },
})

View file

@ -25,8 +25,9 @@ export function limiter({ limit, minutes, key = "" }: {
}, // Method to generate custom identifiers for clients.
// Redis store configuration
store: new RedisStore({
sendCommand: (...args: string[]) => client.sendCommand(args),
}) as any,
// @ts-expect-error - Known issue: the `call` function is not present in @types/ioredis
sendCommand: (...args: string[]) => client.call(...args),
}) as any
})
}

View file

@ -1,42 +1,16 @@
import { createClient, type RedisClientType } from "redis";
import { injectable, type Disposable } from "tsyringe";
import { config } from "../common/config";
import type { AsyncService } from "../common/types/async-service";
import { Redis } from "ioredis";
@injectable()
export class RedisService implements Disposable, AsyncService {
readonly client: RedisClientType;
private isConnected: boolean = false;
export class RedisService implements Disposable {
readonly client: Redis;
constructor() {
this.client = createClient({
url: config.redis.url,
});
this.init();
}
async ensureConnected(): Promise<void> {
if (!this.isConnected) {
await this.init();
}
}
async init(): Promise<void> {
try {
await this.client.connect();
this.isConnected = this.client.isReady;
console.log('Redis connected');
} catch (error) {
console.error('Failed to connect to Redis:', error);
throw error;
}
this.client = new Redis(config.redis.url)
}
async dispose(): Promise<void> {
if (this.isConnected) {
await this.client.disconnect();
this.isConnected = false;
console.log('Redis disconnected');
}
this.client.disconnect();
}
}