@Oury Ba-MSFT
The support ticket indicates that during an update at either the Redis or OS level, as well as during a manual reboot (https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-failover#explanation-of-a-failover), the Redis server will send a FIN network packet to notify the client. If the client's logic can correctly identify the FIN packet, disconnect, and then re-establish the connection, the client can quickly reconnect.
Here's my solution:
const client = redis.createClient(redisConfig);
// REAL CASE should wrapped in async function
client.connect();
client.on('error', async (err) => {
switch (err.message) {
// SOLUTION
case 'Socket closed unexpectedly':
console.log('Closing Redis connection...');
await client.disconnect();
await utils.sleep(3000);
console.log('Trying reconnecting Redis...');
await client.connect();
break;
default:
break;
}
});
I am unable to verify it now, and will have to wait until the next update to confirm if it's effective.