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.
|
}, // Method to generate custom identifiers for clients.
|
||||||
// Redis store configuration
|
// Redis store configuration
|
||||||
store: new RedisStore({
|
store: new RedisStore({
|
||||||
sendCommand: (...args: string[]) => client.sendCommand(args),
|
// @ts-expect-error - Known issue: the `call` function is not present in @types/ioredis
|
||||||
}) as any,
|
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 { injectable, type Disposable } from "tsyringe";
|
||||||
import { config } from "../common/config";
|
import { config } from "../common/config";
|
||||||
import type { AsyncService } from "../common/types/async-service";
|
import { Redis } from "ioredis";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class RedisService implements Disposable, AsyncService {
|
export class RedisService implements Disposable {
|
||||||
readonly client: RedisClientType;
|
readonly client: Redis;
|
||||||
private isConnected: boolean = false;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.client = createClient({
|
this.client = new Redis(config.redis.url)
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async dispose(): Promise<void> {
|
async dispose(): Promise<void> {
|
||||||
if (this.isConnected) {
|
this.client.disconnect();
|
||||||
await this.client.disconnect();
|
|
||||||
this.isConnected = false;
|
|
||||||
console.log('Redis disconnected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue