gpt4 book ai didi

redis - 错误 : Redis connection to 127. 0.0.1:6379 失败 - 连接 ECONNREFUSED

转载 作者:可可西里 更新时间:2023-11-01 11:24:26 31 4
gpt4 key购买 nike

我已经设置了 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)

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

最佳答案

redis.createClient() 尝试连接到本地机器的 redis 服务器并在端口号 6379 上尝试。为此你需要使用以下命令启动 redis 服务器。

redis-server

关于redis - 错误 : Redis connection to 127. 0.0.1:6379 失败 - 连接 ECONNREFUSED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51537703/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com