我正在针对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,但没有成功。
我希望能够在我的构建环境中运行这些测试,但目前我无法检索工作连接。我看不出有什么明显的证据表明我可能会失踪。是否有任何检查可以确保我做正确的事情?