I’m encountering an error in Node.js when using the RedisClient class, even though I only create the class instance once. The issue occurs only in Node.js, everything works fine when I use Python or the Redis Stack console.
For context:
- I’m running Redis Stack in a Docker container on my local machine.
- The same setup works perfectly on my production server (also running Redis Stack in a Docker container).
Any insights?
class RedisClient {
private static instance: RedisClientType;
client: RedisClientType;
constructor() {
if (!RedisClient.instance) {
RedisClient.instance = createClient({
url: ENDPOINT_REDIS,
database: DB_REDIS,
disableOfflineQueue: true,
socket: {
// timeout: 10000,
// reconnectStrategy: (retries) =>
// Math.min(5000 * Math.pow(2, retries), 60000 * 60),
tls: false,
},
});
this.client = RedisClient.instance;
this.connect();
} else {
this.client = RedisClient.instance;
}
}
connect() {
this.client.on("error", (err) => {
console.log("Redis Client Error", err);
});
this.client.on("connect", () => {
console.log("Redis Client Connected");
});
this.client.connect();
}
}
new RedisClient()
Error
Redis Client Error SocketClosedUnexpectedlyError: Socket closed unexpectedly