在尝试使用Redis连接多个套接字io节点时,我的Redis机器与应用程序分离,我必须提供用户名和密码才能访问它,我当前的代码如下所示:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var redis = require('redis');
var redisAdapter = require('socket.io-redis');
var pub = redis.createClient('redis://{username}:{password}@{hostname}:{port}');
var sub = redis.createClient('redis://{username}:{password}@{hostname}:{port}');
io.adapter(redisAdapter({ pubClient: pub, subClient: sub }));
var port = process.env.PORT || 3000;
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
我遇到以下错误:
listening on *:3000
events.js:183
throw er; // Unhandled 'error' event
^
Error: Redis connection to node********.com:6379 failed - connect ETIMEDOUT 109.109.136.70:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
对此我该怎么办?