Skip to content

Commit 80ba1c9

Browse files
committed
replaced node-redis with ioredis for now
1 parent b7a081a commit 80ba1c9

File tree

3 files changed

+8
-40
lines changed

3 files changed

+8
-40
lines changed

src/lib/server/api/databases/redis/schemas/login-requests.schema.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/lib/server/api/middlewares/rate-limiter.middlware.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ export function limiter({ limit, minutes, key = "" }: {
2525
}, // Method to generate custom identifiers for clients.
2626
// Redis store configuration
2727
store: new RedisStore({
28-
sendCommand: (...args: string[]) => client.sendCommand(args),
29-
}) as any,
28+
// @ts-expect-error - Known issue: the `call` function is not present in @types/ioredis
29+
sendCommand: (...args: string[]) => client.call(...args),
30+
}) as any
3031
})
3132
}
3233

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,16 @@
1-
import { createClient, type RedisClientType } from "redis";
21
import { injectable, type Disposable } from "tsyringe";
32
import { config } from "../common/config";
4-
import type { AsyncService } from "../common/types/async-service";
3+
import { Redis } from "ioredis";
54

65
@injectable()
7-
export class RedisService implements Disposable, AsyncService {
8-
readonly client: RedisClientType;
9-
private isConnected: boolean = false;
6+
export class RedisService implements Disposable {
7+
readonly client: Redis;
108

119
constructor() {
12-
this.client = createClient({
13-
url: config.redis.url,
14-
});
15-
this.init();
16-
}
17-
18-
async ensureConnected(): Promise<void> {
19-
if (!this.isConnected) {
20-
await this.init();
21-
}
22-
}
23-
24-
async init(): Promise<void> {
25-
try {
26-
await this.client.connect();
27-
this.isConnected = this.client.isReady;
28-
console.log('Redis connected');
29-
} catch (error) {
30-
console.error('Failed to connect to Redis:', error);
31-
throw error;
32-
}
10+
this.client = new Redis(config.redis.url)
3311
}
3412

3513
async dispose(): Promise<void> {
36-
if (this.isConnected) {
37-
await this.client.disconnect();
38-
this.isConnected = false;
39-
console.log('Redis disconnected');
40-
}
14+
this.client.disconnect();
4115
}
4216
}

0 commit comments

Comments
 (0)