Redis和NodeJS - 连接异常

Aya*_*sha 5 redis node.js

我正在使用Redis DB和NodeJS.偶尔我会遇到异常,我的服务器(NodeJS)崩溃只会重新启动.

Error: Redis connection to localhost:6380 failed - getaddrinfo ENOTFOUND
Run Code Online (Sandbox Code Playgroud)

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

# 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
Run Code Online (Sandbox Code Playgroud)

mač*_*ček 6

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

使用

$ redis-server path/to/redis.conf
Run Code Online (Sandbox Code Playgroud)

此外,默认的 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");
});
Run Code Online (Sandbox Code Playgroud)