I have coding like this
const redis = require("redis");
const client = redis.createClient();
client.on("connect", function() {
console.log("You are now connected");
});
client.set("student", "Laylaa", function(err, reply) {
console.log(reply);
});
but there is an error like this..
events.js:291
throw er; // Unhandled ‘error’ event
^
Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1145:16)
Emitted ‘error’ event on RedisClient instance at:
at RedisClient.on_error (E:TEKNIK INFORMATIKALatihan redisnode_modulesredisindex.js:341:14)
at Socket. (E:TEKNIK INFORMATIKALatihan redisnode_modulesredisindex.js:222:14)
at Socket.emit (events.js:314:20)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: -4078,
code: ‘ECONNREFUSED’,
syscall: ‘connect’,
address: ‘127.0.0.1’,
port: 6379
}
is there a solution? Thanks
2
Answers
You need to first start the redis server by executing:
in a terminal, after redis has been installed and before launching the Node.js client.
You could also add a script to your package.json:
and run:
On Linux Ubuntu you’ll need to run
and Redis will automatically be up and running.Once it’s started, Redis listens on port 6379
.