I have redis installed on my system and its running as well.
from node application, im using below code to work with redis.
redis.js
const redis = require("redis");
let client = redis.createClient(6379, '127.0.0.1', {});
let isRedis = false;
client.on("connect", function () {
console.log(`connected to redis`);
isRedis = true;
});
client.on("error", function (err) {
console.log("redis connection error " + err);
throw err;
});
client.on("end", function (err) {
console.log("redis connection end " + err);
});
module.exports = {
SetRedis,
GetKeys,
GetRedis,
GetKeyRedis,
delRedis
};
im using node index.js command to run the application which should also give me "connected to redis" when the connection is established, but i’m not getting this message on my console .
the npm package is also present in package.json
3
Answers
Working redis.js,
I guess you are making mistake while making connection.
It should have been
rather than
Node Redis 4.x doesn’t allow you to pass in discrete arguments for the host and port. The canonical example of connecting to Redis with Node Redis is this:
If you want to connect to somewhere other than localhost on port 6379, I recommend using a URL. Like this:
But if you want finer control, you can find all the gritty configuration options in the documentation on GitHub.