NodeJs的Redis客户端遇到failed - connect EMFILE错误
程序很简单,就是得到http请求后,用一个参数作为Key去blpop一个Redis实例,如果超时就关掉Redis客户端返回空字典的json,如果超时前得到了push的数据就返回数据,最后关掉Redis连接。
结果在Redis用info得到connected client数量才2000多的时候,Nodejs的redis客户端就开始连接出错,然后报
error:Error: Redis connection to xxx.xxx.xxx.xxx - connect EMFILE
events.js:72
throw er; // Unhandled 'error' event
^
Error: Redis connection to xxx.xxx.xxx.xxx:6379 failed - connect EMFILE
at RedisClient.on_error (/var/www/ncodoon/message/broker/node_modules/redis/index.js:185:24)
at Socket.
<anonymous>
(/var/www/ncodoon/message/broker/node_modules/redis/index.js:95:14)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:415:13)
</anonymous>
Redis所在服务器的ulimit -n 是102400,Nodejs所在服务器的也是这个数。离限制还早得很呢。所以叫改ulimit的可以退散了。