} // TODO use RedisCacheClient private RedisAccess() { _serializer = new NewtonsoftSerializer(); var redisConfiguration = RedisCachingSectionHandler.GetConfig(); RedisCacheClient = new StackExchangeRedisCacheClient(_serializer, redisConfiguration); }
/// <summary> /// Initializes a new instance of the <see cref="StackExchangeRedisCacheClient"/> class. /// </summary> /// <param name="serializer">The serializer.</param> /// <param name="configuration">The configuration.</param> public StackExchangeRedisCacheClient(ISerializer serializer, IRedisCachingConfiguration configuration = null) { if (serializer == null) { throw new ArgumentNullException("serializer"); } if (configuration == null) { configuration = RedisCachingSectionHandler.GetConfig(); } if (configuration == null) { throw new ConfigurationErrorsException("Unable to locate <redisCacheClient> section into your configuration file. Take a look https://github.com/imperugo/StackExchange.Redis.Extensions"); } ConfigurationOptions options = new ConfigurationOptions { Ssl = configuration.Ssl, AllowAdmin = configuration.AllowAdmin }; foreach (RedisHost redisHost in configuration.RedisHosts) { options.EndPoints.Add(redisHost.Host, redisHost.CachePort); } this.connectionMultiplexer = ConnectionMultiplexer.Connect(options); db = connectionMultiplexer.GetDatabase(configuration.Database); this.serializer = serializer; }
public T Read <T>(string key) { serializer = new NewtonsoftSerializer(); var redisConfiguration = RedisCachingSectionHandler.GetConfig(); using (cacheClient = new StackExchangeRedisCacheClient(serializer, redisConfiguration)) { return(cacheClient.Get <T>(key)); } }
public static StackExchangeRedisCacheClient GetClient() { if (config == null) { config = RedisCachingSectionHandler.GetConfig(); } client = new StackExchangeRedisCacheClient(new NewtonsoftSerializer(), config); return(client); }
public bool Save <T>(string key, T value) { bool isSuccess; serializer = new NewtonsoftSerializer(); var redisConfiguration = RedisCachingSectionHandler.GetConfig(); using (cacheClient = new StackExchangeRedisCacheClient(serializer, redisConfiguration)) { isSuccess = cacheClient.Add <T>(key, value); } return(isSuccess); }
public RedisKeyValueStore() { _redisConfiguration = RedisCachingSectionHandler.GetConfig(); var configurationOptions = new ConfigurationOptions { ConnectTimeout = _redisConfiguration.ConnectTimeout, Ssl = _redisConfiguration.Ssl, }; foreach (RedisHost redisHost in _redisConfiguration.RedisHosts) { configurationOptions.EndPoints.Add(redisHost.Host, redisHost.CachePort); } _redis = ConnectionMultiplexer.Connect(configurationOptions); }
public RedisCache() { var configuration = ConfigurationManagerExtension.GetSection("redisCacheClient") as RedisCachingSectionHandler; if (configuration == null) { throw new ConfigurationErrorsException("Unable to locate <redisCacheClient> section into your configuration file. Take a look https://github.com/imperugo/StackExchange.Redis.Extensions"); } var redisConfiguration = RedisCachingSectionHandler.GetConfig(); var connectionPoolManager = new RedisCacheConnectionPoolManager(redisConfiguration); _redis = new RedisCacheClient(connectionPoolManager, new NewtonsoftSerializer(), redisConfiguration).GetDbFromConfiguration(); }
private static void PrepareRedisSessionProvider() { var configuration = RedisCachingSectionHandler.GetConfig(); if (configuration != null) { RedisConnectionConfig.GetSERedisServerConfig = (HttpContextBase context) => { if (configuration.RedisHosts != null && configuration.RedisHosts.Count > 0) { var host = configuration.RedisHosts[0]; return(new KeyValuePair <string, ConfigurationOptions>("DefaultConnection", ConfigurationOptions.Parse(String.Concat(host.Host, ":", host.CachePort)))); } return(new KeyValuePair <string, ConfigurationOptions>()); }; } }
public RedisCache() { var configuration = ConfigurationManagerExtension.GetSection("redisCacheClient") as RedisCachingSectionHandler; if (configuration == null) { throw new ConfigurationErrorsException("Unable to locate <redisCacheClient> section into your configuration file. Take a look https://github.com/imperugo/StackExchange.Redis.Extensions"); } var stringBuilder = new StringBuilder(); using (var stream = new StringWriter(stringBuilder)) { var opts = RedisCachingSectionHandler.GetConfig().ConfigurationOptions; opts.SyncTimeout = 60000; var connectionMultiplexer = (IConnectionMultiplexer)ConnectionMultiplexer.Connect(opts, stream); redis = new StackExchangeRedisCacheClient(connectionMultiplexer, new Serializer()); LogManager.GetLogger("ASC").Debug(stringBuilder.ToString()); } }
public void ReadingFromConfigurationFile_ShouldReturnValidValues() { //NOTE: This isn't a good test, need to find a way to inject a config file in memory (no idea how to do that) var cfg = RedisCachingSectionHandler.GetConfig(); Assert.NotNull(cfg); Assert.NotNull(cfg.ServerEnumerationStrategy); Assert.NotNull(cfg.Hosts); Assert.True(cfg.AllowAdmin); Assert.False(cfg.Ssl); Assert.Equal(3000, cfg.ConnectTimeout); Assert.Equal(24, cfg.Database); Assert.Equal(ServerEnumerationStrategy.ModeOptions.Single, cfg.ServerEnumerationStrategy.Mode); Assert.Equal(ServerEnumerationStrategy.TargetRoleOptions.PreferSlave, cfg.ServerEnumerationStrategy.TargetRole); Assert.Equal(ServerEnumerationStrategy.UnreachableServerActionOptions.IgnoreIfOtherAvailable, cfg.ServerEnumerationStrategy.UnreachableServerAction); Assert.Single(cfg.Hosts); Assert.Equal("127.0.0.1", cfg.Hosts.First().Host); Assert.Equal(6379, cfg.Hosts.First().Port); }
private void ConfigureRedis(IStoveRedisCacheConfiguration redisConfiguration) { redisConfiguration.Configuration = RedisCachingSectionHandler.GetConfig(); if (redisConfiguration.Configuration == null) { throw new StoveException("There is no Redis connection string section in app.config or web.config file, " + "please define redisCacheClient section and configurations. " + "If it is, please make sure of your config file is setted as CopyAlways from it's properties."); } redisConfiguration.ConfigurationOptions = new ConfigurationOptions { AllowAdmin = redisConfiguration.Configuration.AllowAdmin, Ssl = redisConfiguration.Configuration.Ssl, ConnectTimeout = redisConfiguration.Configuration.ConnectTimeout, AbortOnConnectFail = false }; foreach (RedisHost redisHost in redisConfiguration.Configuration.RedisHosts) { redisConfiguration.ConfigurationOptions.EndPoints.Add(redisHost.Host, redisHost.CachePort); } }