Redis cli работает — оба не являются каким-либо клиентом NodeJS Redis

#node.js #redis #windows-subsystem-for-linux #node-redis #ioredis

#node.js #redis #windows-subsystem-for-linux #узел-redis #ioredis

Вопрос:

  1. Я следовал этому руководству: https://redislabs.com/blog/redis-on-windows-10 / для установки следующего: подсистема Windows, Ubuntu и сервер Redis, и, похоже, все работает через Ubuntu-terminal и redis-cli в Windows. Я могу устанавливать и получать значения. Но мои клиенты NodeJS не работают / не могут подключиться (только в самый первый раз?).

  2. Я установил следующий клиент 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, который внезапно не работает.

  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:WorkspaceGitKrakentradebutlercommandernode_modulesredisindex.js:297:23)
    at RedisClient.connection_gone (D:WorkspaceGitKrakentradebutlercommandernode_modulesredisindex.js:602:14)
    at RedisClient.on_error (D:WorkspaceGitKrakentradebutlercommandernode_modulesredisindex.js:345:10)
    at Socket.<anonymous> (D:WorkspaceGitKrakentradebutlercommandernode_modulesredisindex.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)
  
  1. Весь мой Redis-log выглядит так:

14151: C 09 ноября 20:32:56.542 # oOoOoO0OoO0Oo Redis запускается OOO0OOO0OOO0OO 14151: C 09 ноября 20: 32: 56.543 # Redis version = 4.0.9, bits = 64, commit = 00000000, modified = 0, pid = 14151, только что запущен 14151: C 09 ноября 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
  

Комментарии:

1. Похоже, это может быть проблема с разрешениями. Работает ли redis-cli от имени администратора? Является ли узел?

2. У нас есть аналогичная проблема (econnreset) при считывании значения по ключу из redis (с использованием пакета redis). Вы нашли решение или причину?