Redis和NodeJS – 连接exception

我正在使用Redis DB和NodeJS。 偶尔我会得到exception,我的服务器(NodeJS)崩溃只能重新启动。

Error: Redis connection to localhost:6380 failed - getaddrinfo ENOTFOUND 

有人能解释为什么发生这种情况 下面的configuration是否与这个有关?

 # Set the max number of connected clients at the same time. By default # this limit is set to 10000 clients, however if the Redis server is not # able ot configure the process file limit to allow for the specified limit # the max number of allowed clients is set to the current file limit # minus 32 (as Redis reserves a few file descriptors for internal uses). # # Once the limit is reached Redis will close all the new connections sending # an error 'max number of clients reached'. # # maxclients 10000 

这只是意味着你的redis服务器没有运行。 至less不在该地址/端口上。

使用开始您的服务器

 $ redis-server path/to/redis.conf 

此外默认的redis端口是6379 。 如果您在脚本中使用6380,请确保redis正在侦听该端口。


如果脚本中的某些内容导致Redis服务器崩溃,则可以尝试侦听错误以获得更合理的输出

 var redis = require("redis"), client = redis.createClient(6380, "localhost"); client.on("error", function (err) { console.log("Redis error encountered", err); }); client.on("end", function() { console.log("Redis connection closed"); });