static Common() { _rawContext = new RedisContext(Config, new RawSerializer()); _jsonContext = new RedisContext(Config, new JsonSerializer()); _msgPackContext = new RedisContext(Config, new MsgPack.MsgPackSerializer()); #if (NET45 || NET461) _binaryContext = new RedisContext(Config, new BinarySerializer()); All = new[] { _binaryContext, _rawContext, _jsonContext, _msgPackContext }; BinAndRawAndJson = new[] { _binaryContext, _rawContext, _jsonContext }; #else BinAndRawAndJson = new[] { _rawContext, _jsonContext }; All = new[] { _rawContext, _jsonContext, _msgPackContext }; #endif Thread.Sleep(1500); _rawContext.Cache.FlushAll(); // Get the redis version var server = _rawContext.GetConnectionMultiplexer().GetServer(_rawContext.GetConnectionMultiplexer().GetEndPoints()[0]); VersionInfo = server.Info("Server")[0].First(x => x.Key == "redis_version").Value.Split('.').Take(2).Select(x => int.Parse(x)).ToArray(); // Enable keyspace notifications var eventsConfig = server.ConfigGet("notify-keyspace-events"); if (!eventsConfig[0].Value.ToUpper().Contains('K') || !eventsConfig[0].Value.ToUpper().Contains('E')) { server.ConfigSet("notify-keyspace-events", "KEA"); } }
public async Task UT_Context_Dispose_Async(RedisContext context) { var ctx = new RedisContext(context.GetConnectionMultiplexer().Configuration, context.GetSerializer()); await ctx.Cache.SetObjectAsync("key", "value"); ctx.Dispose(); await context.Cache.RemoveAsync("key"); Assert.ThrowsAsync <ObjectDisposedException>(async() => await ctx.Cache.SetObjectAsync("key", "value2")); }
static Common() { var configuration = new ConfigurationBuilder() .AddUserSecrets <UnitTestRedis>() .Build(); var p = configuration["Password"]; if (!string.IsNullOrEmpty(p)) { Config += $",password={p}"; } _rawContext = new RedisContext(Config, new RawSerializer()); _jsonContext = new RedisContext(Config, new JsonSerializer()); _msgPackContext = new RedisContext(Config, new MsgPack.MsgPackSerializer()); _newtonsoftJsonContext = new RedisContext(Config, new NewtonsoftJson.NewtonsoftJsonSerializer()); #if (NET461) _binaryContext = new RedisContext(Config, new BinarySerializer()); All = new[] { _binaryContext, _rawContext, _jsonContext, _msgPackContext, _newtonsoftJsonContext }; BinAndRawAndJson = new[] { _binaryContext, _rawContext, _jsonContext, _newtonsoftJsonContext }; #else BinAndRawAndJson = new[] { _rawContext, _jsonContext, _newtonsoftJsonContext }; All = new[] { _rawContext, _jsonContext, _msgPackContext, _newtonsoftJsonContext }; #endif Thread.Sleep(1500); _rawContext.Cache.FlushAll(); // Get the redis version var server = _rawContext.GetConnectionMultiplexer().GetServer(_rawContext.GetConnectionMultiplexer().GetEndPoints()[0]); VersionInfo = server.Info("Server")[0].First(x => x.Key == "redis_version").Value.Split('.').Take(2).Select(x => int.Parse(x)).ToArray(); // Enable keyspace notifications var eventsConfig = server.ConfigGet("notify-keyspace-events"); if (!eventsConfig[0].Value.ToUpper().Contains('K') || !eventsConfig[0].Value.ToUpper().Contains('E')) { server.ConfigSet("notify-keyspace-events", "KEA"); } }
protected void ForEachRedisRegistered(Action <IConnectionMultiplexer> action) { foreach (var item in lockServerInfos) { var conf = new ConfigurationOptions() { Password = item.Password, }; foreach (var e in item.EndPoints) { conf.EndPoints.Add(e); } var redis = new RedisContext(conf); action(redis.GetConnectionMultiplexer()); } }