public async Task SortedSetRangeByRankWithScore()
        {
            var set = new RedisSortedSet<string>(GlobalSettings.Default, "set");
            await set.Delete();

            await set.Add("a", 10);
            await set.Add("d", 10000);
            await set.Add("b", 100);
            await set.Add("f", 1000000);
            await set.Add("e", 100000);
            await set.Add("c", 1000);

            var range = await set.RangeByRankWithScoresAndRank();
            range.Select(x => x.Value).Is("a", "b", "c", "d", "e", "f");
            range.Select(x => x.Score).Is(10, 100, 1000, 10000, 100000, 1000000);
            range.Select(x => x.Rank).Is(0, 1, 2, 3, 4, 5);

            range = await set.RangeByRankWithScoresAndRank(start: 3); // 3 to last
            range.Select(x => x.Rank).Is(3, 4, 5);

            range = await set.RangeByRankWithScoresAndRank(start: 4, stop: 2);
            range.Length.Is(0);

            range = await set.RangeByRankWithScoresAndRank(order: Order.Descending);
            range.Select(x => x.Value).Is("f", "e", "d", "c", "b", "a");
            range.Select(x => x.Score).Is(1000000, 100000, 10000, 1000, 100, 10);
            range.Select(x => x.Rank).Is(0, 1, 2, 3, 4, 5);

            range = await set.RangeByRankWithScoresAndRank(start: 3, order: Order.Descending); // 3 to last
            range.Select(x => x.Value).Is("c", "b", "a");
            range.Select(x => x.Rank).Is(3, 4, 5);

            range = await set.RangeByRankWithScoresAndRank(start: 2, stop: 4, order: Order.Descending); // 2 to 4
            range.Select(x => x.Value).Is("d", "c", "b");
            range.Select(x => x.Rank).Is(2, 3, 4);

            // start < 0

            range = await set.RangeByRankWithScoresAndRank(start: -1, stop: -1, order: Order.Ascending); // last to last
            range.Select(x => x.Value).Is("f");
            range.Select(x => x.Score).Is(1000000);
            range.Select(x => x.Rank).Is(5);

            range = await set.RangeByRankWithScoresAndRank(start: -3, stop: -2, order: Order.Ascending);
            range.Select(x => x.Value).Is("d", "e");
            range.Select(x => x.Rank).Is(3, 4);

            range = await set.RangeByRankWithScoresAndRank(start: -2, stop: 5, order: Order.Descending);
            range.Select(x => x.Value).Is("b", "a");
            range.Select(x => x.Rank).Is(4, 5);



            range = await set.RangeByRankWithScoresAndRank(start: -100, stop: -120, order: Order.Descending);
            range.Length.Is(0);

        }
Esempio n. 2
0
        public async Task SortedSetRangeByRankWithScore()
        {
            var set = new RedisSortedSet <string>(GlobalSettings.Default, "set");
            await set.Delete();

            await set.Add("a", 10);

            await set.Add("d", 10000);

            await set.Add("b", 100);

            await set.Add("f", 1000000);

            await set.Add("e", 100000);

            await set.Add("c", 1000);

            var range = await set.RangeByRankWithScoresAndRank();

            range.Select(x => x.Value).Is("a", "b", "c", "d", "e", "f");
            range.Select(x => x.Score).Is(10, 100, 1000, 10000, 100000, 1000000);
            range.Select(x => x.Rank).Is(0, 1, 2, 3, 4, 5);

            range = await set.RangeByRankWithScoresAndRank(start : 3); // 3 to last

            range.Select(x => x.Rank).Is(3, 4, 5);

            range = await set.RangeByRankWithScoresAndRank(start : 4, stop : 2);

            range.Length.Is(0);

            range = await set.RangeByRankWithScoresAndRank(order : Order.Descending);

            range.Select(x => x.Value).Is("f", "e", "d", "c", "b", "a");
            range.Select(x => x.Score).Is(1000000, 100000, 10000, 1000, 100, 10);
            range.Select(x => x.Rank).Is(0, 1, 2, 3, 4, 5);

            range = await set.RangeByRankWithScoresAndRank(start : 3, order : Order.Descending); // 3 to last

            range.Select(x => x.Value).Is("c", "b", "a");
            range.Select(x => x.Rank).Is(3, 4, 5);

            range = await set.RangeByRankWithScoresAndRank(start : 2, stop : 4, order : Order.Descending); // 2 to 4

            range.Select(x => x.Value).Is("d", "c", "b");
            range.Select(x => x.Rank).Is(2, 3, 4);

            // start < 0

            range = await set.RangeByRankWithScoresAndRank(start : -1, stop : -1, order : Order.Ascending); // last to last

            range.Select(x => x.Value).Is("f");
            range.Select(x => x.Score).Is(1000000);
            range.Select(x => x.Rank).Is(5);

            range = await set.RangeByRankWithScoresAndRank(start : -3, stop : -2, order : Order.Ascending);

            range.Select(x => x.Value).Is("d", "e");
            range.Select(x => x.Rank).Is(3, 4);

            range = await set.RangeByRankWithScoresAndRank(start : -2, stop : 5, order : Order.Descending);

            range.Select(x => x.Value).Is("b", "a");
            range.Select(x => x.Rank).Is(4, 5);



            range = await set.RangeByRankWithScoresAndRank(start : -100, stop : -120, order : Order.Descending);

            range.Length.Is(0);
        }