错误:Redis与127.0.0.1:6379的连接失败-连接ECONNREFUSED

时间:2018-07-26 11:26:30

标签: redis socket.io

我已经设置了npm,socket.io,redis和redis-server ...,但是我听不懂这个错误:

      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)

代码:

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();
    }); 
});

1 个答案:

答案 0 :(得分:0)

redis.createClient()尝试连接到本地计算机的Redis服务器并尝试使用端口号6379。为此,您需要使用以下命令来启动Redis服务器。

None