public async Task ClassDecrMin() { var v = new RedisClass <MyClass>(settings, "test-hash"); await v.SetField("a", 100); (await v.IncrementLimitByMin("a", -10, 0)).Is(90); (await v.IncrementLimitByMin("a", -20, 0)).Is(70); (await v.IncrementLimitByMin("a", -30, 0)).Is(40); (await v.IncrementLimitByMin("a", -40, 0)).Is(0); (await v.IncrementLimitByMin("a", -50, 0)).Is(0); (await v.GetValue()).a.Is(0); (await v.GetField <int>("a")).Is(0); await v.SetField("b", 100.0); (await v.IncrementLimitByMin("b", -10.5, 0.5)).Is(89.5); (await v.IncrementLimitByMin("b", -20.5, 0.5)).Is(69); (await v.IncrementLimitByMin("b", -40.5, 0.5)).Is(28.5); (await v.IncrementLimitByMin("b", -40.5, 0.5)).Is(0.5); (await v.GetValue()).b.Is(0.5); (await v.GetField <double>("b")).Is(0.5); }
public async Task Class() { var klass = new RedisClass <MyClass>(GlobalSettings.Default, "class"); await klass.Delete(); await klass.Set(new MyClass { Foo = 1000, Bar = "hogehoge", Zoo = 300, Doo = 10.5 }); var mc = await klass.Get(); mc.Foo.Is(1000); mc.Bar.Is("hogehoge"); (await klass.SetMember("Bar", "aiueo")).IsTrue(); (await klass.GetMember(x => x.Bar)).Value.Is("aiueo"); (await klass.SetMember(x => x.Foo, 10000)).IsTrue(); (await klass.GetMember(x => x.Foo)).Value.Is(10000); (await klass.GetMember <int>("nai")).HasValue.IsFalse(); var members = await klass.GetMembers(x => new[] { x.Foo, x.Zoo }); members["Foo"].Is(10000); members["Zoo"].Is(300); await klass.SetMembers(new Dictionary <string, int> { { "Foo", 10 }, { "Zoo", 300 } }); (await klass.GetMember(x => x.Foo)).Value.Is(10); (await klass.GetMember(x => x.Zoo)).Value.Is(300); await klass.SetMembers(x => new[] { x.Foo, x.Zoo }, new[] { 5000, 4000 }); (await klass.GetMember(x => x.Foo)).Value.Is(5000); (await klass.GetMember(x => x.Zoo)).Value.Is(4000); (await klass.Increment("Foo", 100)).Is(5100); (await klass.Increment("Foo", 100)).Is(5200); (await klass.Increment("Foo", -100)).Is(5100); (await klass.GetMember <int>("Foo")).Value.Is(5100); (await klass.IncrementLimitByMax("Foo", 100, 5250)).Is(5200); (await klass.IncrementLimitByMax("Foo", 100, 5250)).Is(5250); (await klass.IncrementLimitByMin("Foo", -3000, 100)).Is(2250); (await klass.IncrementLimitByMin("Foo", -3000, 100)).Is(100); (await klass.Increment(x => x.Foo, 10)).Is(110); (await klass.Increment(x => x.Zooom, 10000)).Is(10000); (await klass.IncrementLimitByMax(x => x.Foo, 500, 140)).Is(140); (await klass.IncrementLimitByMin(x => x.Foo, -500, 30)).Is(30); (await klass.Increment("Doo", 20.1)).Is(30.6); (await klass.Increment("Doo", 20.1)).Is(50.7); Math.Round(await klass.Increment("Doo", -20.3), 1).Is(30.4); Math.Round((await klass.GetMember <double>("Doo")).Value, 1).Is(30.4); Math.Round((await klass.IncrementLimitByMax("Doo", 50.5, 102.4)), 1).Is(80.9); Math.Round((await klass.IncrementLimitByMax("Doo", 50.5, 102.3)), 1).Is(102.3); Math.Round((await klass.IncrementLimitByMin("Doo", -50.4, 30.3)), 1).Is(51.9); Math.Round((await klass.IncrementLimitByMin("Doo", -40.2, 30.3)), 1).Is(30.3); Math.Round((await klass.Increment(x => x.Doo, 20.1)), 1).Is(50.4); Math.Round((await klass.IncrementLimitByMax(x => x.Doo, 909.2, 88.8)), 1).Is(88.8); Math.Round((await klass.IncrementLimitByMin(x => x.Doo, -909.2, 40.4)), 1).Is(40.4); }
public async Task Class() { var klass = new RedisClass<MyClass>(GlobalSettings.Default, "class"); await klass.Delete(); await klass.Set(new MyClass { Foo = 1000, Bar = "hogehoge", Zoo = 300, Doo = 10.5 }); var mc = await klass.Get(); mc.Foo.Is(1000); mc.Bar.Is("hogehoge"); (await klass.SetMember("Bar", "aiueo")).IsTrue(); (await klass.GetMember(x => x.Bar)).Value.Is("aiueo"); (await klass.SetMember(x => x.Foo, 10000)).IsTrue(); (await klass.GetMember(x => x.Foo)).Value.Is(10000); (await klass.GetMember<int>("nai")).HasValue.IsFalse(); var members = await klass.GetMembers(x => new[] { x.Foo, x.Zoo }); members["Foo"].Is(10000); members["Zoo"].Is(300); await klass.SetMembers(new Dictionary<string, int> { {"Foo", 10 }, {"Zoo", 300 } }); (await klass.GetMember(x => x.Foo)).Value.Is(10); (await klass.GetMember(x => x.Zoo)).Value.Is(300); await klass.SetMembers(x => new[] { x.Foo, x.Zoo }, new[] { 5000, 4000 }); (await klass.GetMember(x => x.Foo)).Value.Is(5000); (await klass.GetMember(x => x.Zoo)).Value.Is(4000); (await klass.Increment("Foo", 100)).Is(5100); (await klass.Increment("Foo", 100)).Is(5200); (await klass.Increment("Foo", -100)).Is(5100); (await klass.GetMember<int>("Foo")).Value.Is(5100); (await klass.IncrementLimitByMax("Foo", 100, 5250)).Is(5200); (await klass.IncrementLimitByMax("Foo", 100, 5250)).Is(5250); (await klass.IncrementLimitByMin("Foo", -3000, 100)).Is(2250); (await klass.IncrementLimitByMin("Foo", -3000, 100)).Is(100); (await klass.Increment(x => x.Foo, 10)).Is(110); (await klass.Increment(x => x.Zooom, 10000)).Is(10000); (await klass.IncrementLimitByMax(x => x.Foo, 500, 140)).Is(140); (await klass.IncrementLimitByMin(x => x.Foo, -500, 30)).Is(30); (await klass.Increment("Doo", 20.1)).Is(30.6); (await klass.Increment("Doo", 20.1)).Is(50.7); Math.Round(await klass.Increment("Doo", -20.3), 1).Is(30.4); Math.Round((await klass.GetMember<double>("Doo")).Value, 1).Is(30.4); Math.Round((await klass.IncrementLimitByMax("Doo", 50.5, 102.4)), 1).Is(80.9); Math.Round((await klass.IncrementLimitByMax("Doo", 50.5, 102.3)), 1).Is(102.3); Math.Round((await klass.IncrementLimitByMin("Doo", -50.4, 30.3)), 1).Is(51.9); Math.Round((await klass.IncrementLimitByMin("Doo", -40.2, 30.3)), 1).Is(30.3); Math.Round((await klass.Increment(x => x.Doo, 20.1)), 1).Is(50.4); Math.Round((await klass.IncrementLimitByMax(x => x.Doo, 909.2, 88.8)), 1).Is(88.8); Math.Round((await klass.IncrementLimitByMin(x => x.Doo, -909.2, 40.4)), 1).Is(40.4); }
public async Task ClassDecrMin() { var v = new RedisClass<MyClass>(settings, "test-hash"); await v.SetField("a", 100); (await v.IncrementLimitByMin("a", -10, 0)).Is(90); (await v.IncrementLimitByMin("a", -20, 0)).Is(70); (await v.IncrementLimitByMin("a", -30, 0)).Is(40); (await v.IncrementLimitByMin("a", -40, 0)).Is(0); (await v.IncrementLimitByMin("a", -50, 0)).Is(0); (await v.GetValue()).a.Is(0); (await v.GetField<int>("a")).Is(0); await v.SetField("b", 100.0); (await v.IncrementLimitByMin("b", -10.5, 0.5)).Is(89.5); (await v.IncrementLimitByMin("b", -20.5, 0.5)).Is(69); (await v.IncrementLimitByMin("b", -40.5, 0.5)).Is(28.5); (await v.IncrementLimitByMin("b", -40.5, 0.5)).Is(0.5); (await v.GetValue()).b.Is(0.5); (await v.GetField<double>("b")).Is(0.5); }