Node-redis: Pas de reconnexion

Créé le 9 mars 2019  ·  6Commentaires  ·  Source: NodeRedis/node-redis

Hey,
Je ne peux pas obtenir ce module pour reconnecter redis.

Prenant cette configration:

  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
  });

Je vois le here lorsque j'arrête mon redis local, mais ensuite je le redémarre et j'attends un certain temps, tous les appels redis suivants me donnent:

{ 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.

Des idées? J'ai besoin d'une certaine tolérance pour les redis blips.

question

Commentaire le plus utile

Ouais nous sommes passés à ioredis haha

Tous les 6 commentaires

Même problème sans certaines options comme la file d'attente hors ligne, ma configuration est celle ci-dessous:

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, je ne peux pas croire que je n'ai pas remarqué ce comportement.
J'exécute mes applications avec https://github.com/Unitech/pm2 , qui redémarre l'application chaque fois qu'un échec se produit, donc cela a duré un certain temps inaperçu.

Superbe capture!

Existe-t-il un autre moyen d'accomplir la reconnexion jusqu'à ce qu'elle soit réparée? (Je vois que la dernière version date d'il y a 2 ans)

Ouais nous sommes passés à ioredis haha

@Stono Je suis d'accord, je passe à ioredis aujourd'hui. Il est mis à jour plus souvent, a plus de fonctionnalités et c'est plus rapide.

Merci, ça sonne vraiment mieux, je ne connaissais pas cette bibliothèque.
Sans courtoisie pour ce projet en cours, je ne pourrai pas changer mais c'est bon à savoir pour les travaux futurs.

Cette page vous a été utile?
0 / 5 - 0 notes