Example #1
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");
        }
        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");
        }