I have a Node.js code. While running this code, i have an error.
This error is
ClientClosedError: The client is closed
My redis run on docker called redis1.
const redis = require("redis");
const client = redis.createClient({
host: '127.0.0.1',
port: 6379
});
client.on("error", error => {
if(error) {
console.error("ERROR***",error);
}else {
console.log("Redis connect.");
}
});
//SET
client.set("user_name", "Furkan", (err, msg) => {
if(err) {
console.error("Error while connecting redis", err);
}else {
console.log(msg);
}
})
Furhermore; when i was run this code, dont log in terminal any code. Namely when i was run this code, didnt log in terminal ERROR*** , Redis Connected or Error while connecting redis.
These logs is exists in my code.
this link is reference for me.
How can i fix this code.?
2
Answers
You should add in your code before the client code or set code,
block.
you have to running redis-server on docker.