์ผ,
์ด ๋ชจ๋์ 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์ ์ฝ๊ฐ์ ๊ด์ฉ์ด ํ์ํฉ๋๋ค.
์คํ๋ผ์ธ ๋๊ธฐ์ด๊ณผ ๊ฐ์ ์ผ๋ถ ์ต์ ์ด ์์ผ๋ฉด ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค. ๋ด ๊ตฌ์ฑ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
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๋ ์ ํ ํ ์ ์์ง๋ง ํฅํ ์์
์ ์ํด ์๋ ๊ฒ์ด ์ข์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๊ทธ๋ ์ฐ๋ฆฌ๋ ioredis๋ก ๋ฐ๊ฟจ์ด haha