socket.io redis ECONNREFUSED

时间:2013-08-16 11:54:19

标签: redis socket.io

我的主机允许端口8000到8010

var express = require('express')
  , https = require('https')
  , app = express()
  , cluster = require('cluster')
  , numCPUs = require('os').cpus().length
  , RedisStore = require("socket.io/lib/stores/redis")
  , redis = require("socket.io/node_modules/redis");
  , pub = redis.createClient(8002)
  , sub = redis.createClient(8002)
  , client = redis.createClient(8002);
  , server = https.createServer(options,app);
  , io = require('socket.io').listen(server);
io.set('store',new RedisStore({redisPub:pub,redisSub:sub,redisClient:client}));
if(cluster.isMaster){for(var i=0;i<numCPUs;i++){cluster.fork();}}
else{
  console.log(numCPUs);
  io.sockets.on('connection',function(socket){/*do stuff*/});
  server.listen(8002);
}

我真的很难理解我是否因为端口或者socket.io提供的redis打开而无法连接到redis ...

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: Redis connection to 127.0.0.1:8002 failed - connect ECONNREFUSED
at RedisClient.on_error (/home/engine/public_html/node_modules/socket.io/node_modules/redis/index.js:149:24)
at Socket.<anonymous> (/home/engine/public_html/node_modules/socket.io/node_modules/redis/index.js:83:14)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:426:14
at process._tickCallback (node.js:415:13)
[root@vps ~]#    info  - socket.io started

另外,我不明白这怎么可以给我额外的工作人员(我console.log(numCPUs),它说1,所以这是否意味着我只有1名工人?如果是这样,这意味着没有变化表演;使这项努力毫无意义!?)。

1 个答案:

答案 0 :(得分:0)

您需要安装并运行自己的redis实例,然后使用节点客户端进行连接。

请参阅此主题以获取更多信息,以执行您要执行的操作。

Examples in using RedisStore in socket.io