Node-redis: Tidak ada koneksi ulang

Dibuat pada 9 Mar 2019  ·  6Komentar  ·  Sumber: NodeRedis/node-redis

Hei,
Saya tidak bisa mendapatkan modul ini untuk menyambungkan kembali redis.

Mengambil konfigurasi ini:

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

Saya melihat here ketika saya menghentikan redis lokal, tetapi kemudian saya memulai kembali dan menunggu beberapa saat, panggilan redis berikutnya memberi saya:

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

Ada ide? Saya butuh toleransi untuk redis blip.

question

Komentar yang paling membantu

Ya kami beralih ke ioredis haha

Semua 6 komentar

Masalah yang sama tanpa beberapa opsi seperti antrian offline, konfigurasi saya adalah di bawah ini:

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, tidak percaya saya belum memperhatikan perilaku ini.
Saya menjalankan aplikasi saya dengan https://github.com/Unitech/pm2 , yang memulai ulang aplikasi setiap kali terjadi kegagalan, jadi ini telah berlangsung selama beberapa waktu tanpa disadari.

Tangkapan bagus!

Apakah ada cara lain untuk melakukan penyambungan kembali sampai diperbaiki? (Saya melihat rilis terbaru adalah 2 tahun yang lalu)

Ya kami beralih ke ioredis haha

@Stono saya setuju, saya beralih ke ioredis hari ini. Itu diperbarui lebih sering, memiliki lebih banyak fitur dan lebih cepat.

Terima kasih, ini benar-benar terdengar lebih baik, saya tidak terbiasa dengan perpustakaan ini.
Unfourtantley untuk proyek saat ini, saya tidak akan dapat beralih tetapi ada baiknya mengetahui untuk pekerjaan di masa mendatang.

Apakah halaman ini membantu?
0 / 5 - 0 peringkat

Masalah terkait

twappworld picture twappworld  ·  7Komentar

dotSlashLu picture dotSlashLu  ·  5Komentar

id0Sch picture id0Sch  ·  4Komentar

jackycchen picture jackycchen  ·  4Komentar

juriansluiman picture juriansluiman  ·  3Komentar