public void Configuration_Redis_Properties() { var key = Guid.NewGuid().ToString(); var data = new Dictionary <string, string> { { "redis:0:allowAdmin", "true" }, { "redis:0:connectionTimeout", "123" }, { "redis:0:database", "11" }, { "redis:0:endpoints:0:host", "HostName" }, { "redis:0:endpoints:0:port", "1234" }, { "redis:0:endpoints:1:host", "HostName2" }, { "redis:0:endpoints:1:port", "2222" }, { "redis:0:isSsl", "true" }, { "redis:0:key", key }, { "redis:0:password", "password" }, { "redis:0:sslHost", "sslHost" }, }; GetConfiguration(data).LoadRedisConfigurations(); var redisConfig = RedisConfigurations.GetConfiguration(key); redisConfig.AllowAdmin.Should().BeTrue(); redisConfig.ConnectionString.Should().BeNullOrWhiteSpace(); redisConfig.ConnectionTimeout.Should().Be(123); redisConfig.Database.Should().Be(11); redisConfig.Endpoints[0].Host.Should().Be("HostName"); redisConfig.Endpoints[0].Port.Should().Be(1234); redisConfig.Endpoints[1].Host.Should().Be("HostName2"); redisConfig.Endpoints[1].Port.Should().Be(2222); redisConfig.IsSsl.Should().BeTrue(); redisConfig.Key.Should().Be(key); redisConfig.Password.Should().Be("password"); redisConfig.SslHost.Should().Be("sslHost"); }
public void CacheFactory_Build_WithRedisConfigurationValidateBuilder() { // arrange act CacheFactory.Build <object>(settings => { settings.WithDictionaryHandle(); settings.WithRedisConfiguration("redisBuildUpConfiguration", config => { config.WithAllowAdmin() .WithConnectionTimeout(221113) .WithDatabase(22) .WithEndpoint("127.0.0.1", 2323) .WithEndpoint("nohost", 99999) .WithPassword("secret") .WithSsl("mySslHost"); }); }); var configuration = RedisConfigurations.GetConfiguration("redisBuildUpConfiguration"); // assert configuration.Key.Should().Be("redisBuildUpConfiguration"); configuration.ConnectionTimeout.Should().Be(221113); configuration.Database.Should().Be(22); configuration.Password.Should().Be("secret"); configuration.IsSsl.Should().BeTrue(); configuration.SslHost.Should().Be("mySslHost"); configuration.Endpoints.ShouldBeEquivalentTo(new[] { new ServerEndPoint("127.0.0.1", 2323), new ServerEndPoint("nohost", 99999) }); }
public void Redis_Configurations_LoadWithConnectionString() { string fileName = BaseCacheManagerTest.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config"); RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName); var cfg = RedisConfigurations.GetConfiguration("redisConnectionString"); cfg.ConnectionString.Should().Be("127.0.0.1:6379,allowAdmin=true,ssl=true"); }
public void Configuration_Redis_NothingDefined() { var key = Guid.NewGuid().ToString(); var data = new Dictionary <string, string> { }; GetConfiguration(data).LoadRedisConfigurations(); Action act = () => RedisConfigurations.GetConfiguration(key); act.ShouldThrow <InvalidOperationException>().WithMessage("*" + key + "*"); }
public void Redis_Configurations_LoadWithConnectionString() { string fileName = TestConfigurationHelper.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config"); RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName); var cfg = RedisConfigurations.GetConfiguration("redisConnectionString"); cfg.ConnectionString.ToLower().Should().Contain("127.0.0.1:6379");//,allowAdmin = true,ssl = false"); cfg.ConnectionString.ToLower().Should().Contain("allowadmin=true"); cfg.ConnectionString.ToLower().Should().Contain("ssl=false"); cfg.Database.Should().Be(131); cfg.StrictCompatibilityModeVersion.Should().Be("2.9"); }
public void CacheFactory_Build_ValidateSettings() { // act var act = CacheFactory.Build <string>("stringCache", settings => { settings .WithRedisConfiguration("myRedis", config => { config.WithAllowAdmin() .WithDatabase(0) .WithEndpoint("127.0.0.1", 6379); }) .WithMaxRetries(22) .WithRetryTimeout(2223) .WithUpdateMode(CacheUpdateMode.Full) .WithHandle(typeof(DictionaryCacheHandle <>), "h1") .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromHours(12)) .EnablePerformanceCounters() .And.WithHandle(typeof(DictionaryCacheHandle <>), "h2") .WithExpiration(ExpirationMode.None, TimeSpan.Zero) .DisableStatistics() .And.WithHandle(typeof(DictionaryCacheHandle <>), "h3") .WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(231)) .EnableStatistics(); }); // assert RedisConfigurations.GetConfiguration("myRedis").Should().NotBeNull(); act.Configuration.CacheUpdateMode.Should().Be(CacheUpdateMode.Full); act.Configuration.MaxRetries.Should().Be(22); act.Configuration.RetryTimeout.Should().Be(2223); act.Name.Should().Be("stringCache"); act.CacheHandles.ElementAt(0).Configuration.HandleName.Should().Be("h1"); act.CacheHandles.ElementAt(0).Configuration.EnablePerformanceCounters.Should().BeTrue(); act.CacheHandles.ElementAt(0).Configuration.EnableStatistics.Should().BeTrue(); act.CacheHandles.ElementAt(0).Configuration.ExpirationMode.Should().Be(ExpirationMode.Absolute); act.CacheHandles.ElementAt(0).Configuration.ExpirationTimeout.Should().Be(new TimeSpan(12, 0, 0)); act.CacheHandles.ElementAt(1).Configuration.HandleName.Should().Be("h2"); act.CacheHandles.ElementAt(1).Configuration.EnablePerformanceCounters.Should().BeFalse(); act.CacheHandles.ElementAt(1).Configuration.EnableStatistics.Should().BeFalse(); act.CacheHandles.ElementAt(1).Configuration.ExpirationMode.Should().Be(ExpirationMode.None); act.CacheHandles.ElementAt(1).Configuration.ExpirationTimeout.Should().Be(new TimeSpan(0, 0, 0)); act.CacheHandles.ElementAt(2).Configuration.HandleName.Should().Be("h3"); act.CacheHandles.ElementAt(2).Configuration.EnablePerformanceCounters.Should().BeFalse(); act.CacheHandles.ElementAt(2).Configuration.EnableStatistics.Should().BeTrue(); act.CacheHandles.ElementAt(2).Configuration.ExpirationMode.Should().Be(ExpirationMode.Sliding); act.CacheHandles.ElementAt(2).Configuration.ExpirationTimeout.Should().Be(new TimeSpan(0, 0, 231)); }
public void Configuration_Redis_ConnectionString() { var key = Guid.NewGuid().ToString(); var data = new Dictionary <string, string> { { "redis:1:connectionString", "connectionString" }, { "redis:1:key", key } }; GetConfiguration(data).LoadRedisConfigurations(); var redisConfig = RedisConfigurations.GetConfiguration(key); redisConfig.Key.Should().Be(key); redisConfig.ConnectionString.Should().Be("connectionString"); }
public void Redis_Extensions_WithClientWithDb() { var configKey = Guid.NewGuid().ToString(); var client = ConnectionMultiplexer.Connect("localhost"); var cache = CacheFactory.Build <string>( s => s .WithJsonSerializer() .WithRedisConfiguration(configKey, client, 23) .WithRedisCacheHandle(configKey)); var handle = cache.CacheHandles.OfType <RedisCacheHandle <string> >().First(); var cfg = RedisConfigurations.GetConfiguration(configKey); Assert.Equal(handle.Configuration.Name, configKey); Assert.Equal(23, cfg.Database); Assert.Equal("localhost:6379", cfg.ConnectionString); }
public void CacheFactory_Build_WithRedisConfigurationConnectionString() { // arrange var connection = "127.0.0.1:8080,allowAdmin=true,name=myName,ssl=true"; // act CacheFactory.Build <object>("cacheName", settings => { settings.WithRedisConfiguration("redisWithConnectionString", connection); }); var config = RedisConfigurations.GetConfiguration("redisWithConnectionString"); // assert config.ConnectionString.Should().Be(connection); config.Key.Should().Be("redisWithConnectionString"); }
public RedisCacheBackplane2(CacheManagerConfiguration configuration, ILoggerFactory loggerFactory) : base(configuration) { NotNull(configuration, nameof(configuration)); NotNull(loggerFactory, nameof(loggerFactory)); this.logger = loggerFactory.CreateLogger(this); this.channelName = configuration.BackplaneChannelName ?? "CacheManagerBackplane"; this.identifier = Guid.NewGuid().ToString(); var cfg = RedisConfigurations.GetConfiguration(this.ConfigurationKey); this.connection = new RedisConnectionManager2( cfg, loggerFactory); RetryHelper2.Retry(() => this.Subscribe(), configuration.RetryTimeout, configuration.MaxRetries, this.logger); }
public void Redis_Valid_CfgFile_LoadWithConnectionString() { // arrange string fileName = BaseCacheManagerTest.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config"); string cacheName = "redisConfigFromConnectionString"; // have to load the configuration manually because the file is not avialbale to the default ConfigurtaionManager RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName); var redisConfig = RedisConfigurations.GetConfiguration("redisConnectionString"); // act var cfg = ConfigurationBuilder.LoadConfigurationFile(fileName, cacheName); var cache = CacheFactory.FromConfiguration <object>(cfg); // assert cache.CacheHandles.Any(p => p.Configuration.IsBackplaneSource).Should().BeTrue(); // database is the only option apart from key and connection string which must be set, database will not be set through connection string // to define which database should actually be used... redisConfig.Database.Should().Be(131); }
public void Redis_Valid_CfgFile_LoadWithRedisBackplane() { // arrange string fileName = BaseCacheManagerTest.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config"); string cacheName = "redisConfigFromConfig"; // have to load the configuration manually because the file is not avialbale to the default ConfigurtaionManager RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName); var redisConfig = RedisConfigurations.GetConfiguration("redisFromCfgConfigurationId"); // act var cfg = ConfigurationBuilder.LoadConfigurationFile(fileName, cacheName); var cache = CacheFactory.FromConfiguration <object>(cfg); // assert cache.CacheHandles.Any(p => p.Configuration.IsBackplaneSource).Should().BeTrue(); redisConfig.Database.Should().Be(113); redisConfig.ConnectionTimeout.Should().Be(1200); redisConfig.AllowAdmin.Should().BeTrue(); }
public void Redis_Valid_CfgFile_LoadWithRedisBackplane() { // arrange string fileName = TestConfigurationHelper.GetCfgFileName(@"/Configuration/configuration.valid.allFeatures.config"); string cacheName = "redisConfigFromConfig"; // have to load the configuration manually because the file is not avialbale to the default ConfigurtaionManager RedisConfigurations.LoadConfiguration(fileName, RedisConfigurationSection.DefaultSectionName); var redisConfig = RedisConfigurations.GetConfiguration("redisFromCfgConfigurationId"); // act var cfg = ConfigurationBuilder.LoadConfigurationFile(fileName, cacheName); // assert redisConfig.Database.Should().Be(113); redisConfig.ConnectionTimeout.Should().Be(1200); redisConfig.AllowAdmin.Should().BeTrue(); redisConfig.KeyspaceNotificationsEnabled.Should().BeTrue(); redisConfig.TwemproxyEnabled.Should().BeTrue(); redisConfig.StrictCompatibilityModeVersion.Should().Be("2.7"); }
public void CacheFactory_Build_WithRedisConnectionStringWithProxy() { // arrange var name = Guid.NewGuid().ToString(); var connection = "127.0.0.1:8080,name=myName,ssl=true,proxy=Twemproxy"; var expected = StackExchange.Redis.ConfigurationOptions.Parse(connection); // act CacheFactory.Build <object>(settings => { settings.WithDictionaryHandle(); settings.WithRedisConfiguration(name, connection); }); var config = RedisConfigurations.GetConfiguration(name); // assert config.ConfigurationOptions.Should().BeEquivalentTo(expected); config.TwemproxyEnabled.Should().BeTrue(); config.AllowAdmin.Should().BeFalse(); config.IsSsl.Should().BeTrue(); config.Key.Should().Be(name); }
public void CacheFactory_Build_WithRedisConfigurationValidateBuilder() { // arrange act var name = Guid.NewGuid().ToString(); CacheFactory.Build <object>(settings => { settings.WithDictionaryHandle(); settings.WithRedisConfiguration(name, config => { config .WithAllowAdmin() .UseCompatibilityMode("2.8") .UseTwemproxy() .WithConnectionTimeout(221113) .WithDatabase(22) .WithEndpoint("127.0.0.1", 2323) .WithEndpoint("nohost", 60999) .WithPassword("secret") .WithSsl("mySslHost"); }); }); var configuration = RedisConfigurations.GetConfiguration(name); // assert configuration.Key.Should().Be(name); configuration.ConnectionTimeout.Should().Be(221113); configuration.TwemproxyEnabled.Should().BeTrue(); configuration.StrictCompatibilityModeVersion.Should().Be("2.8"); configuration.Database.Should().Be(22); configuration.Password.Should().Be("secret"); configuration.IsSsl.Should().BeTrue(); configuration.SslHost.Should().Be("mySslHost"); configuration.Endpoints.Should().BeEquivalentTo(new[] { new ServerEndPoint("127.0.0.1", 2323), new ServerEndPoint("nohost", 60999) }); }