1- Is it good practice to use a single Redis instance (Singleton pattern) in the entire NodeJS app?.
2- Will this single Redis connection act as a bottleneck when the server receives more than 10K req/s or 100K req/s?
import { createClient, RedisClientType } from "redis";
class Redis {
private static instance: Redis;
private static client: RedisClientType;
private constructor() {}
public init(url: string) {
Redis.client = createClient({ url });
return Redis.client;
}
static getInstance() {
if (!Redis.instance) Redis.instance = new Redis();
return Redis.instance;
}
public getRedisClient() {
return Redis.client;
}
}
export default Redis.getInstance();