Reputation: 21
I will already setup npm, socket.io, redis and redis-server... but I can't understand this error:
throw er; // Unhandled 'error' event ^ Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0. 1:6379 at Object.exports._errnoException (util.js:1016:11) at exports._exceptionWithHostPort (util.js:1039:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1138:14)
Code:
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var redis = require('redis');
server.listen(8890);
io.on('connection', function (socket) {
console.log("client connected");
var redisClient = redis.createClient();
redisClient.subscribe('message');
redisClient.on("message", function(channel, data) {
console.log("new message add in queue "+ data['message'] + " channel");
socket.emit(channel, data);
});
socket.on('disconnect', function() {
redisClient.quit();
});
});
Upvotes: 1
Views: 4175
Reputation: 722
redis.createClient() tries to connect to the local machine's redis server and try on the port number 6379. For this you need to start the redis server with the following command.
redis-server
Upvotes: 1