I'm using ServiceStack.Redis
in my application, I have a get method that goes to redis (cache) to get some information, but if redis is disconnected, I call the repository to get from the real database
try
{
IEnumerable<GetOrdensByIdQueryDTO> orders = await _redis.GetByHashId<GetOrdensByIdQueryDTO>(request.Account);
if (orders == null || !orders.Any())
return orders.OrderByDescending(order => order.UpdatedAt);
return await GetFromWriteDataBase(request.Account);
}
catch (Exception)
{
return await GetFromWriteDataBase(request.Account);
}
If the redis is disconnected and I call the _redis.GetByHashId()
method, it will throw an exception after 10 seconds, I need to remove this retry exception timer, and throw right before I call it, how can I do that?
I'm injecting Redis like this:
services.AddSingleton<IRedisClientsManager>(serviceProvider =>
{
var cacheConfiguration = serviceProvider.GetRequiredService<CacheConfiguration>();
return new RedisManagerPool(cacheConfiguration.ConnectionString);
});
You can adjust the AutoRetry Timeout with:
RedisConfig.DefaultRetryTimeout = 10000;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.