我正在与StackExchange.Redis客户端一起使用Redis Windows实现.我的问题是,如果初始连接失败,如何处理重新连接尝试.我正在考虑所有Redis主服务器和从服务器都关闭的最坏情况.问题是,每当我的应用程序需要缓存中的某些内容时,它将尝试重新连接到Redis(如果初始连接失败),这非常耗时.我的工厂类看起来像这样:
private ConnectionMultiplexer GetConnection()
{
if (connection != null && connection.IsConnected) return connection;
lock (_lock)
{
if (connection != null && connection.IsConnected) return connection;
if (connection != null)
{
logger.Log("Redis connection disconnected. Disposing connection...");
connection.Dispose();
}
logger.Log("Creating new instance of Redis Connection");
connection = ConnectionMultiplexer.Connect(connectionString.Value);
}
return connection;
}
public IDatabase Database(int? db = null)
{
try
{
return !redisConnectionValid ? null : GetConnection().GetDatabase(db ?? settings.DefaultDb);
}
catch (Exception ex)
{
redisConnectionValid = false;
logger.Log(Level.Error, String.Format("Unable to create Redis …Run Code Online (Sandbox Code Playgroud) OrderActionsBy 似乎可用于控制器内的排序方法,但是排序控制器又如何呢?