مهلا،
لا يمكنني الحصول على هذه الوحدة لإعادة توصيل 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 ، والذي يعيد تشغيل التطبيق عند حدوث فشل ، لذلك استمر هذا لبعض الوقت دون أن يلاحظه أحد.
التقاط رائع!
هل هناك طريقة أخرى لإنجاز إعادة الاتصال حتى يتم إصلاحها؟ (أرى أن أحدث إصدار منذ عامين)
نعم ، لقد تحولنا إلى ioredis هاها
Stono أوافق ، أنا أنتقل إلى
شكرًا ، يبدو الأمر أفضل حقًا ، لم أكن على دراية بهذه المكتبة.
لن أكون قادرًا على التبديل في هذا المشروع الحالي في Unfourtantley ولكن من الجيد معرفة العمل في المستقبل.
التعليق الأكثر فائدة
نعم ، لقد تحولنا إلى ioredis هاها