Пример #1
0
        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);
        }
Пример #2
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);
        }
Пример #3
0
        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);
        }
Пример #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);
        }