try {
const client = createClient({
url: 'redis://redis.xyz.com>:6379'
});
client.on('error', (err) => console.log('Redis Client Error', err));
await client.connect();
await client.set('key', 'value');
const value = await client.get('key');
console.log("Value", value);
}
catch (err: any) {
//Unable to reach here. Redis is not throwing error on redis connection issue
//Want to call api to fetch info when server is down
}
In this, I want to gracefully handle connection timeout if redis connection fails and want that if connection fails than I want to fetch the info from the api in place of redis keep trying to connect to redis server if connection fails.In current settings, if connection fails, system keep trying to connnect to redis server and somewhat blocks the event loop in nodejs.Please suggest how can we avoid this.
2条答案
按热度按时间m0rkklqb1#
e0bqpujr2#
访问https://developer.ibm.com/articles/error-detection-and-handling-with-redis/使用此选项可优雅地处理错误