redis cli工作-两者都不是任何nodejs redis客户端

cwtwac6a  于 2021-06-09  发布在  Redis
关注(0)|答案(0)|浏览(964)

我遵循了以下指南:https://redislabs.com/blog/redis-on-windows-10/ 安装以下组件:windows子系统、ubuntu和redis服务器,一切都通过ubuntu终端和windows中的redis cli运行。我可以设置和获取值。但是我的nodejs客户端不工作/无法连接(只有第一次?)。
我已经安装了以下npm redis客户端:redis(https://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客户端突然不工作。
我还尝试安装另一个客户端: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客户端一起工作,我没有设置任何身份验证/凭据。。。
我没有更改默认conf文件中的任何一行。
我刚刚尝试过安装ubuntu20.04(在运行18.04之前)并再次从头开始安装redis,但结果是一样的:redis cli可以工作,但nodejs客户端都没有(现在甚至不是第一次)。
在我捕捉到“重新连接”和“连接”事件之后,它抛出异常,然后在循环中一遍又一遍地运行这些步骤。所以它似乎可以连接,但有什么东西会马上断开它?
第六章。我得到这个错误消息(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,
    code: 'ECONNRESET',
    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)

我的整个redis日志如下所示:
14151:c 09 11月20:32:56.542Šoo0oooooo redis is starting oo0oooooooo 14151:c 09 11月20:32:56.543Šredis version=4.0.9,bits=64,commit=00000000,modified=0,pid=14151,just started 14151:c 09 11月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, bits=64, commit=00000000, modified=0, 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, bits=64, commit=00000000, modified=0, 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, bits=64, commit=00000000, modified=0, 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

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题