mirror of
https://github.com/BradNut/TofuStack
synced 2025-09-08 17:40:26 +00:00
replaced node-redis with ioredis for now
This commit is contained in:
parent
b7a081a941
commit
80ba1c9861
3 changed files with 8 additions and 40 deletions
|
|
@ -1,7 +0,0 @@
|
|||
import { Schema } from 'redis-om'
|
||||
|
||||
export const loginRequestSchema = new Schema('album', {
|
||||
id: { type: 'string' },
|
||||
hashedToken: { type: 'string' },
|
||||
email: { type: 'string' },
|
||||
})
|
||||
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue