कनेक्शन त्रुटियों को error के रूप में रिपोर्ट किया जाता है क्लाइंट पर इवेंट Redis वस्तु।
डॉक्स के "ऑटो-रीकनेक्ट" अनुभाग के अनुसार, जब रेडिस से कनेक्शन खो जाता है (या, संभवतः, पहली जगह में स्थापित करने में असमर्थ) ioredis स्वचालित रूप से पुन:कनेक्ट करने का प्रयास करेगा। केवल maxRetriesPerRequest . के बाद प्रयास लंबित आदेशों को "एक त्रुटि के साथ फ़्लश किया जाएगा", यानी catch पर पहुंचें यहाँ:
try {
cachedItem = await redisClient.get(queryString); // This emit an error on the redis client, because it fails to connect (that's intended, to test the behaviour)
} catch (e) {
logger.error(e); // It never goes there, as the error isn't "thrown", but rather "emitted" and handled by redis its own way
epsagon.setError(e);
}
चूंकि आप पहली त्रुटि पर अपना प्रोग्राम रोकते हैं:
client.on('error', function (e) {
// ...
if (e.message === 'ERR invalid password') {
logger.error(`Fatal error occurred "${e.message}". Stopping server.`);
throw e; // Fatal error, don't attempt to fix
...पुन:प्रयास और बाद में "एक त्रुटि के साथ फ्लशिंग" को कभी भी चलने का मौका नहीं मिलता है।
client.on('error' . में त्रुटियों पर ध्यान न दें , और आपको await redisClient.get() . से त्रुटि वापस मिलनी चाहिए ।