Hi All,
I am having a very annoying issue that i hope that someone can help with.
Background: We have moved to ServiceStack.Redis.Core from StackExchange.Redis for the Sentinel offerings. We needed a more stable Redis cluster on our application. We are running a microservices architecture with asp.net core 2.2 and docker swarm. The shopping basket is stored in Redis under the users GUID. We also use it to cache users login information and any temporary data.
This is the code that i am using to connect to Redis sentinel in the Startup.cs under ConfigureServices. Ignore the else statement that is just so that we can run Redis locally for debugging purposes.
Startup.cs
// register redis sentinel
ServiceStack.Licensing.RegisterLicense("LICENCE_KEY");
if (!Environment.IsEnvironment("Local"))
{
RedisConfig.DefaultConnectTimeout = 5;
RedisConfig.DefaultIdleTimeOutSecs = 1;
RedisPoolConfig redisPoolConfig = new RedisPoolConfig() { MaxPoolSize = 1000 };
var sentinel = new RedisSentinel("REDIS_SENTINEL_DOCKER_CONTAINER_NAME")
{
RedisManagerFactory = (master, slaves) => new RedisManagerPool(master, redisPoolConfig)
};
services.AddScoped<IRedisClientsManager>(c => sentinel.Start());
services.AddScoped<IRedisClient>(c => c.GetService<IRedisClientsManager>().GetClient());
}
else
{
services.AddScoped<IRedisClientsManager>(c => new RedisManagerPool(Configuration["ConnectionString"]));
services.AddScoped<IRedisClient>(c => c.GetService<IRedisClientsManager>().GetClient());
}
BasketRepository.cs
private readonly ILogger<RedisBasketRepository> _logger;
private readonly IRedisClient _cache;
public RedisBasketRepository(ILoggerFactory loggerFactory, IRedisClient cache)
{
_logger = loggerFactory.CreateLogger<RedisBasketRepository>();
_cache = cache;
}
public async Task<BasketItem> GetBasketItemAsync(Guid userId, Guid itemId)
{
BasketItem basketItem = null;
CustomerBasket customerBasket = null;
var data = _cache.Get<string>(userId.ToString());
customerBasket = JsonConvert.DeserializeObject<CustomerBasket>(data);
basketItem = customerBasket.Items.SingleOrDefault(s => s.Id == itemId);
return basketItem;
}
Now to the problem, We have absolutely no problems for the first 50 or so requests (there are 2 Redis connections on the same page so more like 100 connection) and the page load speed is lightning fast then the page hangs and loads for roughly 10 seconds or so, then goes back to its lighting fast load speeds.
My initial thoughts are that the connections are not being free’d up and the wait period is them getting disposed.
I have tried adding the IRedisClientsManager & IRedisClient as Singletons and Transient, I have also tried just injecting the IRedisClientsManager and wrapping the IRedisClient into a using statement for each query. The same thing happens in every instance
I have tried playing around with the default RedisConfig
RedisConfig.DefaultConnectTimeout = 5;
RedisConfig.DefaultIdleTimeOutSecs = 1;
RedisConfig.DefaultRetryTimeout = 1000;
etc
Am i missing a setting somewhere or could this be to do with my sentinel setup, i mean its a very basic setup on docker with 3 sentinels, 1 master and 4 replicas.
Any help would be very much appreciated.
Joe.