nodejs在redis失败时终止

我正在使用Node.js,Express,Redis和Socket.io。 当Redisclosures时,Node.js将终止。

我怎样才能防止这个,可能是代码重新连接或什么地方?

输出:

info - socket.io started Express server listening on port 3000 

错误:

 events.js:72 throw er; // Unhandled 'error' event ^ Error: Redis connection to 127.0.0.1:6380 failed - connect ECONNREFUSED at RedisClient.on_error (...../node_modules/redis/index.js:151:24) at Socket.<anonymous> (...../node_modules/redis/index.js:86:14) at Socket.EventEmitter.emit (events.js:95:17) at net.js:426:14 at process._tickCallback (node.js:415:13) 

好像你没有为你的redis客户端实例提供一个error handling程序。 你能提供你的代码摘录吗? 也许我们可以更好地帮助你。 只是一个错误消息是less一点。

如果我不得不猜测那么我会说你没有error handling程序…

看到这里: https : //github.com/mranney/node_redis#usage

你有错误的callback?

例:

 var redis = require("redis"), client = redis.createClient(); // This is required so your error doesn't bubble // upwards and kills your instance client.on("error", function (err) { console.log("Error " + err); }); 

node_redis客户端自动重新连接,所以你不需要处理,尽pipe你可以configuration一个max_attempts和其他选项。 看到这里: https : //github.com/mranney/node_redis#rediscreateclientport-host-options

我希望我能提供一些有用的信息