Here is my code sample:
const redis = require('redis');
const client = redis.createClient({
url: '127.0.0.1',
password: 'password',
disableOfflineQueue: true,
socket: {
timeout: 1000,
connectTimeout: 1000,
tls: true
},
});
client.on('error', (err) => console.log('Redis Client Error', err));
// Connection is on here
client.connect().then(async () => {
// I disconnect the network here and expected to get an error and handle it
const value = await client.get('key'); // <--- application hangs here
// this code has never been executed
await client.quit();
console.log(value);
}).catch(err => console.log(err));
My application hangs indefinitely if connection lost for some reasons and I want to handle this case. I try to catch every possible errors but it doesn't help - application hangs on get() method and nothing happens.
So I just need to handle redis error on lost connection to be able to log this error and move next in my code.
Environment:
- Node.js Version: v16.13.0
- Redis Server Version: 6.0.5
- Node Redis Version: 4.2.0
- Platform: Unknown
Here is my code sample:
My application hangs indefinitely if connection lost for some reasons and I want to handle this case. I try to catch every possible errors but it doesn't help - application hangs on get() method and nothing happens.
So I just need to handle redis error on lost connection to be able to log this error and move next in my code.
Environment: