Пример #1
0
        /// <summary>
        /// ZRANGE, ZREVRANGE http://redis.io/commands/zrange http://redis.io/commands/zrevrange
        /// </summary>
        public Task <SortedSetResultWithRank <T>[]> RangeByRankWithScoresAndRank(long start = 0, long stop = -1, Order order = Order.Ascending, CommandFlags commandFlags = CommandFlags.None)
        {
            return(TraceHelper.RecordSendAndReceive(Settings, Key, CallType, async() =>
            {
                SortedSetEntry[] rs;
                long startIndex = 0;
                if (start >= 0)
                {
                    rs = await Command.SortedSetRangeByRankWithScoresAsync(Key, start, stop, order, commandFlags).ForAwait();
                    startIndex = start;
                }
                else
                {
                    var tx = CreateTransaction();
                    var lengthFuture = tx.SortedSetLengthAsync(Key, flags: commandFlags);
                    var rsFuture = tx.SortedSetRangeByRankWithScoresAsync(Key, start, stop, order, commandFlags);
                    await tx.ExecuteAsync(commandFlags).ForAwait();
                    rs = await rsFuture.ForAwait();
                    var length = await lengthFuture.ForAwait();

                    startIndex = length + start;
                }

                long size = 0;
                var result = rs.Select((x, i) =>
                {
                    long s;
                    var v = Settings.ValueConverter.Deserialize <T>(x.Element, out s);
                    size += s;
                    var rank = startIndex + i;
                    return new SortedSetResultWithRank <T>(v, x.Score, rank);
                }).ToArray();

                return Tracing.CreateSentAndReceived(new { start, stop, order }, sizeof(long) * 2, result, size);
            }));
        }