Node-redis: ๋‹ค์‹œ ์—ฐ๊ฒฐํ•˜์ง€ ์•Š์Œ

์— ๋งŒ๋“  2019๋…„ 03์›” 09์ผ  ยท  6์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: NodeRedis/node-redis

์•ผ,
์ด ๋ชจ๋“ˆ์„ redis์— ๋‹ค์‹œ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์ด ๊ตฌ์„ฑ :

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

๋‚ด ๋กœ์ปฌ redis๋ฅผ ์ค‘์ง€ํ•˜๋ฉด here ๊ฐ€ ํ‘œ์‹œ๋˜์ง€๋งŒ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๊ณ  ์–ผ๋งˆ ๋™์•ˆ ๊ธฐ๋‹ค๋ฆฌ๋ฉด ํ›„์† redis ํ˜ธ์ถœ์ด ๋‚˜์—๊ฒŒ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค.

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

์–ด๋–ค ์•„์ด๋””์–ด? redis blips์— ์•ฝ๊ฐ„์˜ ๊ด€์šฉ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

question

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๊ทธ๋ž˜ ์šฐ๋ฆฌ๋Š” ioredis๋กœ ๋ฐ”๊ฟจ์–ด haha

๋ชจ๋“  6 ๋Œ“๊ธ€

์˜คํ”„๋ผ์ธ ๋Œ€๊ธฐ์—ด๊ณผ ๊ฐ™์€ ์ผ๋ถ€ ์˜ต์…˜์ด ์—†์œผ๋ฉด ๋™์ผํ•œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๋‚ด ๊ตฌ์„ฑ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

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

์™€, ๋‚ด๊ฐ€์ด ํ–‰๋™์„ ์•Œ์•„ ์ฐจ๋ฆฌ์ง€ ๋ชปํ–ˆ๋‹ค ๋‹ˆ ๋ฏฟ์„ ์ˆ˜๊ฐ€ ์—†๋„ค์š”.
https://github.com/Unitech/pm2๋กœ ๋‚ด ์•ฑ์„ ์‹คํ–‰ํ•˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ๋•Œ๋งˆ๋‹ค ์•ฑ์ด ๋‹ค์‹œ ์‹œ์ž‘๋˜๋ฏ€๋กœ ๋ˆˆ์น˜ ์ฑ„์ง€ ๋ชปํ•œ ์ฑ„ ๊ฝค ์˜ค๋žซ๋™์•ˆ ๊ณ„์†๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ ˆ์ดํŠธ ์บ์น˜!

์ˆ˜์ • ๋  ๋•Œ๊นŒ์ง€ ์žฌ ์—ฐ๊ฒฐ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๊นŒ? (์ตœ์‹  ๋ฆด๋ฆฌ์Šค๋Š” 2 ๋…„ ์ „์ž…๋‹ˆ๋‹ค)

๊ทธ๋ž˜ ์šฐ๋ฆฌ๋Š” ioredis๋กœ ๋ฐ”๊ฟจ์–ด haha

@Stono ๋™์˜ํ•ฉ๋‹ˆ๋‹ค. ์˜ค๋Š˜ ioredis๋กœ ์ „ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๋” ์ž์ฃผ ์—…๋ฐ์ดํŠธ๋˜๊ณ  ๋” ๋งŽ์€ ๊ธฐ๋Šฅ์ด ์žˆ์œผ๋ฉฐ fassttterr์ž…๋‹ˆ๋‹ค.

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ •๋ง ์ข‹๊ฒŒ ๋“ค๋ฆฝ๋‹ˆ๋‹ค.์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ์ต์ˆ™ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
์ด ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์˜ Unfourtantley๋Š” ์ „ํ™˜ ํ•  ์ˆ˜ ์—†์ง€๋งŒ ํ–ฅํ›„ ์ž‘์—…์„ ์œ„ํ•ด ์•„๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰