public void Redis_ValueConverter_Poco_Update() { var cache = TestManagers.CreateRedisCache(17, false, Serializer.Json); // act/assert using (cache) { var key = Guid.NewGuid().ToString(); var region = Guid.NewGuid().ToString(); var value = new Poco() { Id = 23, Something = "§asdad" }; cache.Add(key, value, region); var newValue = new Poco() { Id = 24, Something = "%!else$&" }; object resultValue = null; Func <bool> act = () => cache.TryUpdate(key, region, (o) => newValue, out resultValue); act().Should().BeTrue(); newValue.ShouldBeEquivalentTo(resultValue); } }
public void Redis_ValueConverter_CacheTypeConversion_Poco() { var cache = TestManagers.CreateRedisCache <Poco>(17, false, Serializer.Json); // act/assert using (cache) { var key = Guid.NewGuid().ToString(); var value = new Poco() { Id = 23, Something = "§asdad" }; cache.Add(key, value); var result = (Poco)cache.Get(key); value.ShouldBeEquivalentTo(result); } }
public async Task Redis_ValidateVersion_AddPutGetUpdate() { var configKey = Guid.NewGuid().ToString(); var multi = ConnectionMultiplexer.Connect("localhost"); var cache = CacheFactory.Build <Poco>( s => s .WithRedisConfiguration(configKey, multi) .WithBondCompactBinarySerializer() .WithRedisCacheHandle(configKey)); // don't keep it and also dispose it later (seems appveyor doesn't like too many open connections) RedisConnectionManager.RemoveConnection(multi.Configuration); // act/assert using (multi) using (cache) { var key = Guid.NewGuid().ToString(); var value = new Poco() { Id = 23, Something = "§asdad" }; cache.Add(key, value); await Task.Delay(10); var version = (int)multi.GetDatabase(0).HashGet(key, "version"); version.Should().Be(1); cache.Put(key, value); await Task.Delay(10); version = (int)multi.GetDatabase(0).HashGet(key, "version"); version.Should().Be(2); cache.Update(key, r => { r.Something = "new text"; return(r); }); await Task.Delay(10); version = (int)multi.GetDatabase(0).HashGet(key, "version"); version.Should().Be(3); cache.Get(key).Something.Should().Be("new text"); } }
public void Redis_ValidateVersion_AddPutGetUpdate() { var configKey = Guid.NewGuid().ToString(); var multi = ConnectionMultiplexer.Connect("localhost"); var cache = CacheFactory.Build <Poco>( s => s .WithRedisConfiguration(configKey, multi) .WithJsonSerializer() .WithRedisCacheHandle(configKey)); // act/assert using (cache) { var key = Guid.NewGuid().ToString(); var value = new Poco() { Id = 23, Something = "§asdad" }; cache.Add(key, value); Thread.Sleep(10); var version = (int)multi.GetDatabase(0).HashGet(key, "version"); version.Should().Be(1); cache.Put(key, value); Thread.Sleep(10); version = (int)multi.GetDatabase(0).HashGet(key, "version"); version.Should().Be(2); cache.Update(key, r => { r.Something = "new text"; return(r); }); Thread.Sleep(10); version = (int)multi.GetDatabase(0).HashGet(key, "version"); version.Should().Be(3); cache.Get(key).Something.Should().Be("new text"); } }