Ejemplo n.º 1
0
        public async Task DictionaryIncr()
        {
            var dict = new RedisDictionary <string, long>(GlobalSettings.Default, "dict");
            await dict.Delete();

            (await dict.Increment("hogehoge", 100)).Is(100);
            (await dict.Increment("hogehoge", 100)).Is(200);
            (await dict.Increment("hogehoge", -100)).Is(100);
            (await dict.Get("hogehoge")).Value.Is(100);

            (await dict.IncrementLimitByMax("hogehoge", 40, 150)).Is(140);
            (await dict.IncrementLimitByMax("hogehoge", 40, 150)).Is(150);
            (await dict.IncrementLimitByMin("hogehoge", -40, 100)).Is(110);
            (await dict.IncrementLimitByMin("hogehoge", -40, 100)).Is(100);

            var dict2 = new RedisDictionary <string, double>(GlobalSettings.Default, "dict2");
            await dict2.Delete();

            (await dict2.Increment("hogehoge", 100.5)).Is(100.5);
            (await dict2.Increment("hogehoge", 100.0)).Is(200.5);
            (await dict2.Increment("hogehoge", -100.0)).Is(100.5);
            (await dict2.Get("hogehoge")).Value.Is(100.5);

            (await dict2.IncrementLimitByMax("hogehoge", 40.1, 150.9)).Is(140.6);
            (await dict2.IncrementLimitByMax("hogehoge", 40.3, 150.9)).Is(150.9);
            (await dict2.IncrementLimitByMin("hogehoge", -40.1, 100.9)).Is(110.8);
            (await dict2.IncrementLimitByMin("hogehoge", -40.3, 100.9)).Is(100.9);
        }
Ejemplo n.º 2
0
        public async Task DictIncrMax()
        {
            var v = new RedisDictionary <int>(settings, "test-hash");

            await v.Set("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.Get("a")).Is(100);

            var v2 = new RedisDictionary <double>(settings, "test-hash");
            await v2.Set("a", 0);

            (await v2.IncrementLimitByMax("a", 10.5, 100)).Is(10.5);
            (await v2.IncrementLimitByMax("a", 20.5, 100)).Is(31);
            (await v2.IncrementLimitByMax("a", 40.5, 100)).Is(71.5);
            (await v2.IncrementLimitByMax("a", 40.5, 100.1)).Is(100.1);
            (await v2.IncrementLimitByMax("a", 50.0, 100)).Is(100);

            (await v2.Get("a")).Is(100);
        }
Ejemplo n.º 3
0
        public async Task DictionaryIncr()
        {
            var dict = new RedisDictionary<string, long>(GlobalSettings.Default, "dict");
            await dict.Delete();

            (await dict.Increment("hogehoge", 100)).Is(100);
            (await dict.Increment("hogehoge", 100)).Is(200);
            (await dict.Increment("hogehoge", -100)).Is(100);
            (await dict.Get("hogehoge")).Value.Is(100);

            (await dict.IncrementLimitByMax("hogehoge", 40, 150)).Is(140);
            (await dict.IncrementLimitByMax("hogehoge", 40, 150)).Is(150);
            (await dict.IncrementLimitByMin("hogehoge", -40, 100)).Is(110);
            (await dict.IncrementLimitByMin("hogehoge", -40, 100)).Is(100);

            var dict2 = new RedisDictionary<string, double>(GlobalSettings.Default, "dict2");
            await dict2.Delete();
            (await dict2.Increment("hogehoge", 100.5)).Is(100.5);
            (await dict2.Increment("hogehoge", 100.0)).Is(200.5);
            (await dict2.Increment("hogehoge", -100.0)).Is(100.5);
            (await dict2.Get("hogehoge")).Value.Is(100.5);

            (await dict2.IncrementLimitByMax("hogehoge", 40.1, 150.9)).Is(140.6);
            (await dict2.IncrementLimitByMax("hogehoge", 40.3, 150.9)).Is(150.9);
            (await dict2.IncrementLimitByMin("hogehoge", -40.1, 100.9)).Is(110.8);
            (await dict2.IncrementLimitByMin("hogehoge", -40.3, 100.9)).Is(100.9);
        }
Ejemplo n.º 4
0
        public async Task DictIncrMax()
        {
            var v = new RedisDictionary<int>(settings, "test-hash");

            await v.Set("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.Get("a")).Is(100);

            var v2 = new RedisDictionary<double>(settings, "test-hash");
            await v2.Set("a", 0);
            (await v2.IncrementLimitByMax("a", 10.5, 100)).Is(10.5);
            (await v2.IncrementLimitByMax("a", 20.5, 100)).Is(31);
            (await v2.IncrementLimitByMax("a", 40.5, 100)).Is(71.5);
            (await v2.IncrementLimitByMax("a", 40.5, 100.1)).Is(100.1);
            (await v2.IncrementLimitByMax("a", 50.0, 100)).Is(100);

            (await v2.Get("a")).Is(100);
        }