I am developing a microservice architecture application where I am using a Redis Cache to cache frequently used information. The issue is that the number of connected clients is constantly increasing and I don't know why.
I am accessing the Redis Cache from an ASP.NET Web API and a Web Job. The NuGet package used for connection is "StackExchange.Redis" (https://github.com/StackExchange/StackExchange.Redis).
The way I am connecting to Redis in code is as follows:
connection = ConnectionMultiplexer.Connect(configurationOptions);
connection.ConnectionFailed += ConnectionFailed;
connection.ConnectionRestored += ConnectionRestored;
connection.InternalError += InternalError;
if (!connection.IsConnected)
{
//_traceSource.TraceWarning($"Connection to REDIS '{_endpointAddress}' was not established.");
}
database = connection.GetDatabase();
return database;
In addition, I have implemented the Dispose() method to make sure that connections are disconnected properly:
public void Dispose()
{
connection?.Close(true);
}