9

我将 Redis DB 与 NodeJS 一起使用。有时我会遇到异常并且我的服务器(NodeJS)崩溃只是再次重新启动。

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

有人可以解释为什么会这样吗?以下配置与此有关吗?

# 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
4

1 回答 1

7

这仅仅意味着你的 redis 服务器没有运行;至少不在那个地址/端口上。

使用启动服务器

$ 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");
});
于 2013-11-05T08:38:01.570 回答