Redis CLI工作-并非所有NodeJS Redis客户端

问题描述

  1. 我已按照本指南进行操作:https://redislabs.com/blog/redis-on-windows-10/安装以下内容:Windows子系统,Ubuntu和Redis Server,一切似乎都可以通过Windows的Ubuntu终端和redis-cli运行。我可以设置并获取值。但是我的NodeJS客户端无法工作/无法连接(仅是第一次?)。

  2. 我已经安装了以下NPM Redis客户端:redishttps://www.npmjs.com/package/redis)。

const redis = require("redis");
const client = redis.createClient();
 
client.on("error",function(error) {
  console.error(error);
});
 
client.set("key","value",redis.print);
client.get("key",redis.print);

第一次解决(它可以设置并读取名为“ key”的键)!但是从此以后!!我尝试关闭并打开Ubuntu终端,重新启动Redis服务器等,但似乎无济于事。 redis-cli始终在ubuntu终端上正常工作-只是NodeJS客户端突然不起作用。

  1. 我还尝试安装另一个客户端:https://www.npmjs.com/package/ioredis但是问题仍然存在,并且相同。我这样连接此客户端:
const Redis = require("ioredis");
const redis = new Redis({
    port: 6379,// Redis port
    host: "127.0.0.1",// Redis host
    family: 4,// 4 (IPv4) or 6 (IPv6)
    db: 0,});

// ioredis supports all Redis commands:
redis.set("foo","bar"); // returns promise which resolves to string,"OK"

// Or ioredis returns a promise if the last argument isn't a function
redis.get("foo").then(function (result) {
    console.log(result); // Prints "bar"
});

再次,它第一次与第一个Redis客户端一起使用时,我没有设置任何身份验证/凭据...

  1. 我尚未更改认conf文件中的任何一行。

  2. 我刚刚尝试安装Ubuntu 20.04(在运行18.04之前),然后再次从头开始安装Redis-但是结果是一样的:Redis cli工作但没有NodeJS客户端(甚至不是第一次)现在)。

它引发异常,并且在我可以捕获到“重新连接”和“连接”事件之后-然后,它一次又一次地循环运行这些步骤。这样看来它可以连接,但之后又有什么断开连接?

6a。我收到此错误消息(NPM:Redis):

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:209:20) {
  errno: -4077,code: 'ECONNRESET',syscall: 'read'
}
AbortError: Ready check Failed: Redis connection lost and command aborted. It might have been processed.
    at RedisClient.flush_and_error (D:\Workspace\GitKraken\Tradebutlercommander\node_modules\redis\index.js:297:23)
    at RedisClient.connection_gone (D:\Workspace\GitKraken\Tradebutlercommander\node_modules\redis\index.js:602:14)
    at RedisClient.on_error (D:\Workspace\GitKraken\Tradebutlercommander\node_modules\redis\index.js:345:10)
    at Socket.<anonymous> (D:\Workspace\GitKraken\Tradebutlercommander\node_modules\redis\index.js:222:14)
    at Socket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processticksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'UNCERTAIN_STATE',command: 'INFO',origin: Error: read ECONNRESET
      at TCP.onStreamRead (internal/stream_base_commons.js:209:20) {
    errno: -4077,syscall: 'read'
  }
}

6b。或者现在我在使用NPM时收到以下错误消息:ioredis

[ioredis] Unhandled error event: Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
    at TCP.callbackTrampoline (internal/async_hooks.js:129:14)
  1. 我的整个Redis日志如下:

14151:C 09 Nov 20:32:56.542#oO0OoO0OoO0Oo Redis正在启动 oO0OoO0OoO0Oo 14151:C 09 Nov 20:32:56.543#Redis版本= 4.0.9, 位= 64,提交= 00000000,已修改= 0,pid = 14151,刚刚开始14151:C 09 Nov 20:32:56.543#配置已加载

14152:M 09 Nov 20:32:56.546 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
14152:M 09 Nov 20:32:56.546 # Server initialized
14152:M 09 Nov 20:32:56.546 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
14152:M 09 Nov 20:32:56.546 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root,and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
14152:M 09 Nov 20:32:56.546 * Ready to accept connections
14152:M 09 Nov 20:47:57.089 * 1 changes in 900 seconds. Saving...
14152:M 09 Nov 20:47:57.092 * Background saving started by pid 14157
14157:C 09 Nov 20:47:57.103 * DB saved on disk
14157:C 09 Nov 20:47:57.104 * RDB: 2 MB of memory used by copy-on-write
14152:M 09 Nov 20:47:57.193 * Background saving terminated with success
14152:M 09 Nov 22:52:57.784 * 1 changes in 900 seconds. Saving...
14152:M 09 Nov 22:52:57.785 * Background saving started by pid 14158
14158:C 09 Nov 22:52:57.794 * DB saved on disk
14158:C 09 Nov 22:52:57.794 * RDB: 2 MB of memory used by copy-on-write
14152:M 09 Nov 22:52:57.886 * Background saving terminated with success
14152:M 09 Nov 23:07:58.080 * 1 changes in 900 seconds. Saving...
14152:M 09 Nov 23:07:58.081 * Background saving started by pid 14159
14159:C 09 Nov 23:07:58.089 * DB saved on disk
14159:C 09 Nov 23:07:58.090 * RDB: 2 MB of memory used by copy-on-write
14152:M 09 Nov 23:07:58.182 * Background saving terminated with success
14152:signal-handler (1604949420) Received SIGTERM scheduling shutdown...
14152:M 09 Nov 23:17:00.243 # User requested shutdown...
14152:M 09 Nov 23:17:00.243 * Saving the final RDB snapshot before exiting.
14152:M 09 Nov 23:17:00.248 * DB saved on disk
14152:M 09 Nov 23:17:00.248 * Removing the pid file.
14152:M 09 Nov 23:17:00.248 # Redis is Now ready to exit,bye bye...
14182:C 09 Nov 23:17:01.275 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
14182:C 09 Nov 23:17:01.275 # Redis version=4.0.9,bits=64,commit=00000000,modified=0,pid=14182,just started
14182:C 09 Nov 23:17:01.275 # Configuration loaded  

14183:M 09 Nov 23:17:01.276 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
14183:M 09 Nov 23:17:01.276 # Server initialized
14183:M 09 Nov 23:17:01.277 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
14183:M 09 Nov 23:17:01.277 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root,and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
14183:M 09 Nov 23:17:01.277 * DB loaded from disk: 0.000 seconds
14183:M 09 Nov 23:17:01.277 * Ready to accept connections
14183:M 09 Nov 23:32:02.032 * 1 changes in 900 seconds. Saving...
14183:M 09 Nov 23:32:02.033 * Background saving started by pid 14195
14195:C 09 Nov 23:32:02.037 * DB saved on disk
14195:C 09 Nov 23:32:02.037 * RDB: 2 MB of memory used by copy-on-write
14183:M 09 Nov 23:32:02.134 * Background saving terminated with success
14183:signal-handler (1604976838) Received SIGTERM scheduling shutdown...
14183:M 10 Nov 06:53:58.489 # User requested shutdown...
14183:M 10 Nov 06:53:58.489 * Saving the final RDB snapshot before exiting.
14183:M 10 Nov 06:53:58.500 * DB saved on disk
14183:M 10 Nov 06:53:58.500 * Removing the pid file.
14183:M 10 Nov 06:53:58.500 # Redis is Now ready to exit,bye bye...
14218:C 10 Nov 06:53:59.528 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
14218:C 10 Nov 06:53:59.528 # Redis version=4.0.9,pid=14218,just started
14218:C 10 Nov 06:53:59.528 # Configuration loaded

14219:M 10 Nov 06:53:59.530 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
14219:M 10 Nov 06:53:59.530 # Server initialized
14219:M 10 Nov 06:53:59.530 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
14219:M 10 Nov 06:53:59.530 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root,and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
14219:M 10 Nov 06:53:59.530 * DB loaded from disk: 0.000 seconds
14219:M 10 Nov 06:53:59.530 * Ready to accept connections
14219:signal-handler (1604985108) Received SIGTERM scheduling shutdown...
14219:M 10 Nov 09:11:48.604 # User requested shutdown...
14219:M 10 Nov 09:11:48.604 * Saving the final RDB snapshot before exiting.
14219:M 10 Nov 09:11:48.612 * DB saved on disk
14219:M 10 Nov 09:11:48.612 * Removing the pid file.
14219:M 10 Nov 09:11:48.612 # Redis is Now ready to exit,bye bye...
14252:C 10 Nov 09:11:49.645 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
14252:C 10 Nov 09:11:49.645 # Redis version=4.0.9,pid=14252,just started
14252:C 10 Nov 09:11:49.645 # Configuration loaded

14253:M 10 Nov 09:11:49.648 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
14253:M 10 Nov 09:11:49.648 # Server initialized
14253:M 10 Nov 09:11:49.648 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
14253:M 10 Nov 09:11:49.648 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root,and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
14253:M 10 Nov 09:11:49.648 * DB loaded from disk: 0.000 seconds
14253:M 10 Nov 09:11:49.648 * Ready to accept connections
14253:signal-handler (1604987303) Received SIGTERM scheduling shutdown...
14253:M 10 Nov 09:48:24.076 # User requested shutdown...
14253:M 10 Nov 09:48:24.076 * Saving the final RDB snapshot before exiting.
14253:M 10 Nov 09:48:24.089 * DB saved on disk
14253:M 10 Nov 09:48:24.089 * Removing the pid file.
14253:M 10 Nov 09:48:24.089 # Redis is Now ready to exit,bye bye...
14280:C 10 Nov 09:48:25.139 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
14280:C 10 Nov 09:48:25.139 # Redis version=4.0.9,pid=14280,just started
14280:C 10 Nov 09:48:25.139 # Configuration loaded

14281:M 10 Nov 09:48:25.144 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
14281:M 10 Nov 09:48:25.144 # Server initialized
14281:M 10 Nov 09:48:25.144 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
14281:M 10 Nov 09:48:25.144 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root,and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
14281:M 10 Nov 09:48:25.144 * DB loaded from disk: 0.000 seconds
14281:M 10 Nov 09:48:25.144 * Ready to accept connections

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)