ΠΡΠΈΠ²Π΅Ρ,
Π― Π½Π΅ ΠΌΠΎΠ³Ρ Π·Π°ΡΡΠ°Π²ΠΈΡΡ ΡΡΠΎΡ ΠΌΠΎΠ΄ΡΠ»Ρ ΠΏΠ΅ΡΠ΅ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠΈΡΡ 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
});
Π― Π²ΠΈΠΆΡ here
ΠΊΠΎΠ³Π΄Π° ΠΎΡΡΠ°Π½Π°Π²Π»ΠΈΠ²Π°Ρ Π»ΠΎΠΊΠ°Π»ΡΠ½ΡΠΉ redis, Π½ΠΎ Π·Π°ΡΠ΅ΠΌ ΠΏΠ΅ΡΠ΅Π·Π°ΠΏΡΡΠΊΠ°Ρ Π΅Π³ΠΎ ΡΠ½ΠΎΠ²Π° ΠΈ ΠΆΠ΄Ρ Π»ΡΠ±ΠΎΠ΅ Π²ΡΠ΅ΠΌΡ, Π»ΡΠ±ΡΠ΅ ΠΏΠΎΡΠ»Π΅Π΄ΡΡΡΠΈΠ΅ Π²ΡΠ·ΠΎΠ²Ρ 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.
ΠΡΡΡ ΠΈΠ΄Π΅ΠΈ? ΠΠ½Π΅ Π½ΡΠΆΠ½Π° Π½Π΅ΠΊΠΎΡΠΎΡΠ°Ρ ΡΠ΅ΡΠΏΠΈΠΌΠΎΡΡΡ ΠΊ ΠΊΡΠ°ΡΠ½ΡΠΌ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡΠΌ.
Π’Π° ΠΆΠ΅ ΠΏΡΠΎΠ±Π»Π΅ΠΌΠ° Π±Π΅Π· Π½Π΅ΠΊΠΎΡΠΎΡΡΡ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠΎΠ², ΡΠ°ΠΊΠΈΡ ΠΊΠ°ΠΊ ΠΎΡΠ΅ΡΠ΅Π΄Ρ Π² Π°Π²ΡΠΎΠ½ΠΎΠΌΠ½ΠΎΠΌ ΡΠ΅ΠΆΠΈΠΌΠ΅, ΠΌΠΎΡ ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΡ ΠΏΡΠΈΠ²Π΅Π΄Π΅Π½Π° Π½ΠΈΠΆΠ΅:
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, Ρ Π°-Ρ Π°
@Stono Π‘ΠΎΠ³Π»Π°ΡΠ΅Π½, ΡΠ΅Π³ΠΎΠ΄Π½Ρ Ρ ΠΏΠ΅ΡΠ΅Ρ ΠΎΠΆΡ Π½Π°
Π‘ΠΏΠ°ΡΠΈΠ±ΠΎ, Π΄Π΅ΠΉΡΡΠ²ΠΈΡΠ΅Π»ΡΠ½ΠΎ Π·Π²ΡΡΠΈΡ Π»ΡΡΡΠ΅, Ρ Π½Π΅ Π±ΡΠ» Π·Π½Π°ΠΊΠΎΠΌ Ρ ΡΡΠΎΠΉ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠΎΠΉ.
Unfourtantley Π΄Π»Ρ ΡΡΠΎΠ³ΠΎ ΡΠ΅ΠΊΡΡΠ΅Π³ΠΎ ΠΏΡΠΎΠ΅ΠΊΡΠ° Ρ Π½Π΅ ΡΠΌΠΎΠ³Ρ ΠΏΠ΅ΡΠ΅ΠΊΠ»ΡΡΠΈΡΡΡΡ, Π½ΠΎ Ρ
ΠΎΡΠΎΡΠΎ Π·Π½Π°ΡΡ Π΄Π»Ρ Π±ΡΠ΄ΡΡΠ΅ΠΉ ΡΠ°Π±ΠΎΡΡ.
Π‘Π°ΠΌΡΠΉ ΠΏΠΎΠ»Π΅Π·Π½ΡΠΉ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΠΉ
ΠΠ°, ΠΌΡ ΠΏΠ΅ΡΠ΅ΡΠ»ΠΈ Π½Π° ioredis, Ρ Π°-Ρ Π°