我正在針對Azure Redis緩存運行集成測試。這是我非常簡單的緩存實現:Azure Redis緩存:是否可以在集成測試中連接到緩存?
public class RedisCacheEngine : ICacheEngine
{
private static readonly Lazy<ConnectionMultiplexer> LazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
var config = new ConfigurationService();
var connectionString = config.Get("Redis.ConnectionString");
var connection = ConnectionMultiplexer.Connect(connectionString);
return connection;
});
private static ConnectionMultiplexer Connection => LazyConnection.Value;
public TValue Get<TValue>(string key) where TValue : class
{
var redisValue = Connection.GetDatabase().StringGet(key);
return redisValue == RedisValue.Null
? default(TValue)
: JsonConvert.DeserializeObject<TValue>(redisValue);
}
public void Set<TValue>(string key, TValue value) where TValue : class =>
Connection.GetDatabase().StringSet(key, JsonConvert.SerializeObject(value));
public void Remove(string key) => Connection.GetDatabase().KeyDelete(key);
}
當我看到在調試器中connection
對象,其failureMessage
場寫着「SocketFailure上PING」。我不相信服務器超時,因爲超時窗口很慷慨五秒,而且我正在一個快速的系統上,連接速度很快。
連接字符串是一個標準的Redis天青緩存串,形式
myapp.redis.cache.windows.net:6380,password=___,ssl=True,abortConnect=False
我的嘗試設置ssl = False,但沒有成功。
我希望能夠在我的構建環境中運行這些測試,但目前我無法檢索工作連接。我看不出有什麼明顯的證據表明我可能會失蹤。是否有任何檢查可以確保我做正確的事情?