【发布时间】:2016-02-18 11:59:41
【问题描述】:
我正在使用 node-redis 模块连接到 redis。
因此,我附加了一个事件侦听器来处理无法建立 redis 服务器连接的情况。
client = redis.createClient(6379, 'localhost')
client.on('error',(err)=>{
console.log('redis connection refused')
})
这是在没有监听器的情况下发生的错误。
events.js:141
throw er; // Unhandled 'error' event
^
Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:837:11)
at exports._exceptionWithHostPort (util.js:860:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1060:14)
现在我的问题是,这个事件监听器什么时候附加到“客户端”。是否有可能在附加事件监听器之前抛出连接被拒绝错误?
【问题讨论】:
标签: javascript node.js node-redis