ねえ、
このモジュールで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するのにある程度の耐性が必要です。
オフラインキューなどのオプションがない場合も同じ問題が発生します。私の構成は次のとおりです。
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年前だと思います)
ええ、ioredishahaに切り替えました
@Stono同意します、今日はioredisに切り替えます。 それはより頻繁に更新され、より多くの機能を備えており、最も魅力的です。
おかげで、それは本当に良く聞こえます、私はこのライブラリに慣れていませんでした。
この現在のプロジェクトのUnfourtantleyは切り替えることができませんが、将来の作業のために知っておくとよいでしょう。
最も参考になるコメント
ええ、ioredishahaに切り替えました