Esempio n. 1
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);
        }
Esempio n. 2
0
        public async Task DictionaryAdd()
        {
            var dict = new RedisDictionary <string, int>(GlobalSettings.Default, "dict");
            await dict.Delete();

            (await dict.Set("a", -1)).IsTrue();
            (await dict.Set("a", 0)).IsFalse(); // already exists
            (await dict.Set("b", 1)).IsTrue();
            (await dict.Set("b", -1, when: When.NotExists)).IsFalse();
            (await dict.Set("c", 2)).IsTrue();
            (await dict.Set("d", 3)).IsTrue();
            await dict.Set(new Dictionary <string, int> {
                { "e", 4 }, { "f", 5 }
            });

            var xs = (await dict.GetAll()).OrderBy(x => x.Key).ToArray();

            xs.Select(x => x.Key).Is("a", "b", "c", "d", "e", "f");
            xs.Select(x => x.Value).Is(0, 1, 2, 3, 4, 5);
            (await dict.Keys()).OrderBy(x => x).Is("a", "b", "c", "d", "e", "f");
            (await dict.Values()).OrderBy(x => x).Is(0, 1, 2, 3, 4, 5);
            (await dict.Length()).Is(6);

            (await dict.Exists("a")).IsTrue();
            (await dict.Exists("z")).IsFalse();

            (await dict.Get("a")).Value.Is(0);
            (await dict.Get("c")).Value.Is(2);
            (await dict.Get("z")).HasValue.IsFalse();

            var mget = (await dict.Get(new[] { "a", "b", "u", "d", "z" })).OrderBy(x => x.Key).ToArray();

            mget.Select(x => x.Key).Is("a", "b", "d");
            mget.Select(x => x.Value).Is(0, 1, 3);

            (await dict.Delete("c")).IsTrue();
            (await dict.Delete("c")).IsFalse();
            (await dict.Keys()).OrderBy(x => x).Is("a", "b", "d", "e", "f");

            (await dict.Delete(new[] { "a", "c", "d", "z" })).Is(2);
            (await dict.Keys()).OrderBy(x => x).Is("b", "e", "f");
        }
Esempio n. 3
0
        public async Task DictDecrMin()
        {
            var v = new RedisDictionary <int>(settings, "test-hash");

            await v.Set("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", -42, 0)).Is(0);
            (await v.IncrementLimitByMin("a", -50, 0)).Is(0);

            (await v.Get("a")).Is(0);

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

            (await v2.IncrementLimitByMin("a", -10.5, 0.5)).Is(89.5);
            (await v2.IncrementLimitByMin("a", -20.5, 0.5)).Is(69);
            (await v2.IncrementLimitByMin("a", -40.5, 0.5)).Is(28.5);
            (await v2.IncrementLimitByMin("a", -40.5, 0.5)).Is(0.5);

            (await v2.Get("a")).Is(0.5);
        }
        public async Task DictionaryAdd()
        {
            var dict = new RedisDictionary<string, int>(GlobalSettings.Default, "dict");
            await dict.Delete();

            (await dict.Set("a", -1)).IsTrue();
            (await dict.Set("a", 0)).IsFalse(); // already exists
            (await dict.Set("b", 1)).IsTrue();
            (await dict.Set("b", -1, when: When.NotExists)).IsFalse();
            (await dict.Set("c", 2)).IsTrue();
            (await dict.Set("d", 3)).IsTrue();
            await dict.Set(new Dictionary<string, int> { { "e", 4 }, { "f", 5 } });

            var xs = (await dict.GetAll()).OrderBy(x => x.Key).ToArray();
            xs.Select(x => x.Key).Is("a", "b", "c", "d", "e", "f");
            xs.Select(x => x.Value).Is(0, 1, 2, 3, 4, 5);
            (await dict.Keys()).OrderBy(x => x).Is("a", "b", "c", "d", "e", "f");
            (await dict.Values()).OrderBy(x => x).Is(0, 1, 2, 3, 4, 5);
            (await dict.Length()).Is(6);

            (await dict.Exists("a")).IsTrue();
            (await dict.Exists("z")).IsFalse();

            (await dict.Get("a")).Value.Is(0);
            (await dict.Get("c")).Value.Is(2);
            (await dict.Get("z")).HasValue.IsFalse();

            var mget = (await dict.Get(new[] { "a", "b", "u", "d", "z" })).OrderBy(x => x.Key).ToArray();
            mget.Select(x => x.Key).Is("a", "b", "d");
            mget.Select(x => x.Value).Is(0, 1, 3);

            (await dict.Delete("c")).IsTrue();
            (await dict.Delete("c")).IsFalse();
            (await dict.Keys()).OrderBy(x => x).Is("a", "b", "d", "e", "f");

            (await dict.Delete(new[] { "a", "c", "d", "z" })).Is(2);
            (await dict.Keys()).OrderBy(x => x).Is("b", "e", "f");
        }
Esempio n. 5
0
        public async Task DictDecrMin()
        {
            var v = new RedisDictionary<int>(settings, "test-hash");

            await v.Set("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", -42, 0)).Is(0);
            (await v.IncrementLimitByMin("a", -50, 0)).Is(0);

            (await v.Get("a")).Is(0);

            var v2 = new RedisDictionary<double>(settings, "test-hash");
            await v2.Set("a", 100);
            (await v2.IncrementLimitByMin("a", -10.5, 0.5)).Is(89.5);
            (await v2.IncrementLimitByMin("a", -20.5, 0.5)).Is(69);
            (await v2.IncrementLimitByMin("a", -40.5, 0.5)).Is(28.5);
            (await v2.IncrementLimitByMin("a", -40.5, 0.5)).Is(0.5);

            (await v2.Get("a")).Is(0.5);
        }
Esempio n. 6
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);
        }