Beispiel #1
0
        public async Task ClassIncrMax()
        {
            var v = new RedisClass <MyClass>(settings, "test-hash");

            await v.SetField("a", 0);

            (await v.IncrementLimitByMax("a", 10, 100)).Is(10);
            (await v.IncrementLimitByMax("a", 20, 100)).Is(30);
            (await v.IncrementLimitByMax("a", 30, 100)).Is(60);
            (await v.IncrementLimitByMax("a", 40, 100)).Is(100);
            (await v.IncrementLimitByMax("a", 50, 100)).Is(100);

            (await v.GetValue()).a.Is(100);
            (await v.GetField <int>("a")).Is(100);

            await v.SetField("b", 0.0);

            (await v.IncrementLimitByMax("b", 10.5, 100)).Is(10.5);
            (await v.IncrementLimitByMax("b", 20.5, 100)).Is(31);
            (await v.IncrementLimitByMax("b", 40.5, 100)).Is(71.5);
            (await v.IncrementLimitByMax("b", 40.5, 100.1)).Is(100.1);

            (await v.GetValue()).b.Is(100.1);
            (await v.GetField <double>("b")).Is(100.1);
        }
Beispiel #2
0
        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);
        }
Beispiel #4
0
        public async Task ClassIncrMax()
        {
            var v = new RedisClass<MyClass>(settings, "test-hash");

            await v.SetField("a", 0);
            (await v.IncrementLimitByMax("a", 10, 100)).Is(10);
            (await v.IncrementLimitByMax("a", 20, 100)).Is(30);
            (await v.IncrementLimitByMax("a", 30, 100)).Is(60);
            (await v.IncrementLimitByMax("a", 40, 100)).Is(100);
            (await v.IncrementLimitByMax("a", 50, 100)).Is(100);

            (await v.GetValue()).a.Is(100);
            (await v.GetField<int>("a")).Is(100);

            await v.SetField("b", 0.0);
            (await v.IncrementLimitByMax("b", 10.5, 100)).Is(10.5);
            (await v.IncrementLimitByMax("b", 20.5, 100)).Is(31);
            (await v.IncrementLimitByMax("b", 40.5, 100)).Is(71.5);
            (await v.IncrementLimitByMax("b", 40.5, 100.1)).Is(100.1);
            
            (await v.GetValue()).b.Is(100.1);
            (await v.GetField<double>("b")).Is(100.1);
        }