Node-redis: Keine erneute Verbindung

Erstellt am 9. März 2019  ·  6Kommentare  ·  Quelle: NodeRedis/node-redis

Hallo,
Ich kann dieses Modul nicht dazu bringen, Redis wieder zu verbinden.

Diese Konfigration nehmen:

  const client = redis.createClient({
    no_ready_check: false,
    enable_offline_queue: true,
    retry_unfulfilled_commands: true,
    socket_keepalive: true,
    retry_strategy: function (options) {
      if (options.error && options.error.code === 'ECONNREFUSED') {
        // End reconnecting on a specific error and flush all commands with
        // a individual error
        return new Error('The server refused the connection');
      }
      if (options.total_retry_time > 1000 * 60 * 60) {
        // End reconnecting after a specific timeout and flush all commands
        // with a individual error
        return new Error('Retry time exhausted');
      }
      if (options.attempt > 10) {
        // End reconnecting with built in error
        return undefined;
      }
      console.log('here');
      // reconnect after
      return 100;
    },
    host: process.env.REDIS_HOST || '127.0.0.1',
    port: 6379
  });

Ich sehe die here wenn ich meine lokalen Redis stoppe, aber dann starte ich sie erneut und warte eine beliebige Zeitspanne, alle nachfolgenden Redis-Aufrufe geben mir:

{ AbortError: EXEC can't be processed. The connection is already closed.
    at handle_offline_command (/Users/kstoney/git/autotrader/platform-alert-forwarder/node_modules/redis/index.js:851:15)
    at RedisClient.internal_send_command (/Users/kstoney/git/autotrader/platform-alert-forwarder/node_modules/redis/index.js:885:9)
    at Multi.exec_transaction (/Users/kstoney/git/autotrader/platform-alert-forwarder/node_modules/redis/lib/multi.js:115:18)
    at Object.RedisCache.self.set (/Users/kstoney/git/autotrader/platform-alert-forwarder/lib/caches/redis.js:41:8)
    at Object.sendMessage [as handle] (/Users/kstoney/git/autotrader/platform-alert-forwarder/lib/forwarders/slack.js:197:28)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
  command: 'EXEC',
  code: 'NR_CLOSED',
  errors:
   [ { AbortError: SET can't be processed. The connection is already closed.

Irgendwelche Ideen? Ich brauche etwas Toleranz gegenüber Redis Blips.

question

Hilfreichster Kommentar

Ja, wir sind zu ioredis gewechselt, haha

Alle 6 Kommentare

Gleiches Problem ohne einige Optionen wie Warteschlange offline, meine Konfiguration ist die folgende:

var client = redis.createClient({
    port: process.env.REDIS_PORT,
    host: process.env.REDIS_HOST,
    retry_strategy: function (options) {
        if (options.error && options.error.code === 'ECONNREFUSED') {
            // End reconnecting on a specific error and flush all commands with
            // a individual error
            logger.debug('[Redis Strategy] - Connection Refused options:', options);
            return new Error('The server refused the connection');
        }
        if (options.total_retry_time > 1000 * 60 * 60) {
            // End reconnecting after a specific timeout and flush all commands
            // with a individual error
            logger.debug('[Redis Strategy] - Time exhausted options:', options);
            return new Error('Retry time exhausted');
        }
        if (options.attempt > 10) {
            // End reconnecting with built in error
            return undefined;
        }
        // reconnect after
        return Math.min(options.attempt * 100, 3000);
    }
});

client.on('connect', function () {
    console.log('Redis client connected');
});

client.on('error', function (err) {
    console.log('Something went wrong ' + err);
});

Wow, ich kann nicht glauben, dass ich dieses Verhalten nicht bemerkt habe.
Ich führe meine Apps mit https://github.com/Unitech/pm2 aus , wodurch die App immer dann neu gestartet wird, wenn ein Fehler auftritt. Dies ist also seit einiger Zeit unbemerkt.

Großer Fang!

Gibt es eine andere Möglichkeit, die Wiederverbindung herzustellen, bis sie behoben ist? (Ich sehe die neueste Version ist vor 2 Jahren)

Ja, wir sind zu ioredis gewechselt, haha

@ Tono Ich stimme zu, ich wechsle heute zu

Danke, es klingt wirklich besser, ich war mit dieser Bibliothek nicht vertraut.
Unfourtantley für dieses aktuelle Projekt werde ich nicht wechseln können, aber es ist gut zu wissen für zukünftige Arbeit.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen