Example #1
0
        public List <string> GetSortedEntryValues(string setId, int startingFrom, int endingAt)
        {
            var sortOptions = new SortOptions {
                Skip = startingFrom, Take = endingAt,
            };
            var multiDataList = Sort(setId, sortOptions);

            return(multiDataList.ToStringList());
        }
Example #2
0
        public List <string> GetRangeFromSortedList(string listId, int startingFrom, int endingAt)
        {
            var sortOptions = new SortOptions {
                Skip = startingFrom, Take = endingAt, SortAlpha = true
            };
            var multiDataList = Sort(listId, sortOptions);

            return(multiDataList.ToStringList());
        }
Example #3
0
        public byte[][] Sort(string listOrSetId, SortOptions sortOptions)
        {
            var cmdWithArgs = new List <byte[]>
            {
                Commands.Sort, listOrSetId.ToUtf8Bytes()
            };

            if (sortOptions.SortPattern != null)
            {
                cmdWithArgs.Add(Commands.By);
                cmdWithArgs.Add(sortOptions.SortPattern.ToUtf8Bytes());
            }

            if (sortOptions.Skip.HasValue || sortOptions.Take.HasValue)
            {
                cmdWithArgs.Add(Commands.Limit);
                cmdWithArgs.Add(sortOptions.Skip.GetValueOrDefault(0).ToUtf8Bytes());
                cmdWithArgs.Add(sortOptions.Take.GetValueOrDefault(0).ToUtf8Bytes());
            }

            if (sortOptions.GetPattern != null)
            {
                cmdWithArgs.Add(Commands.Get);
                cmdWithArgs.Add(sortOptions.GetPattern.ToUtf8Bytes());
            }

            if (sortOptions.SortDesc)
            {
                cmdWithArgs.Add(Commands.Desc);
            }

            if (sortOptions.SortAlpha)
            {
                cmdWithArgs.Add(Commands.Alpha);
            }

            if (sortOptions.StoreAtKey != null)
            {
                cmdWithArgs.Add(Commands.Store);
                cmdWithArgs.Add(sortOptions.StoreAtKey.ToUtf8Bytes());
            }

            return(SendExpectMultiData(cmdWithArgs.ToArray()));
        }
        public List <string> GetSortedItemsFromList(string listId, SortOptions sortOptions)
        {
            var multiDataList = Sort(listId, sortOptions);

            return(multiDataList.ToStringList());
        }
        public byte[][] Sort(string listOrSetId, SortOptions sortOptions)
        {
            var cmdWithArgs = new List<byte[]>
           	{
           		Commands.Sort, listOrSetId.ToUtf8Bytes()
           	};

            if (sortOptions.SortPattern != null)
            {
                cmdWithArgs.Add(Commands.By);
                cmdWithArgs.Add(sortOptions.SortPattern.ToUtf8Bytes());
            }

            if (sortOptions.Skip.HasValue || sortOptions.Take.HasValue)
            {
                cmdWithArgs.Add(Commands.Limit);
                cmdWithArgs.Add(sortOptions.Skip.GetValueOrDefault(0).ToUtf8Bytes());
                cmdWithArgs.Add(sortOptions.Take.GetValueOrDefault(0).ToUtf8Bytes());
            }

            if (sortOptions.GetPattern != null)
            {
                cmdWithArgs.Add(Commands.Get);
                cmdWithArgs.Add(sortOptions.GetPattern.ToUtf8Bytes());
            }

            if (sortOptions.SortDesc)
            {
                cmdWithArgs.Add(Commands.Desc);
            }

            if (sortOptions.SortAlpha)
            {
                cmdWithArgs.Add(Commands.Alpha);
            }

            if (sortOptions.StoreAtKey != null)
            {
                cmdWithArgs.Add(Commands.Store);
                cmdWithArgs.Add(sortOptions.StoreAtKey.ToUtf8Bytes());
            }

            return SendExpectMultiData(cmdWithArgs.ToArray());
        }
        public void Compare_sort_nosort_to_smembers_mget()
        {
            string setKey = "setKey";
            int total = 25;
            int count = 20;
            var temp = new byte[1];
            byte fixedValue = 124;
            temp[0] = fixedValue;

            //initialize set and individual keys
            Redis.Del(setKey);
            for (var i = 0; i < total; ++i)
            {
                string key = setKey + i;
                Redis.SAdd(setKey, key.ToUtf8Bytes());
                Redis.Set(key, temp);
            }

            var sw = Stopwatch.StartNew();

            byte[][] results = null;
            for (int i = 0; i < count; ++i)
            {
                var keys = Redis.SMembers(setKey);
                results = Redis.MGet(keys);

            }

            sw.Stop();

            //make sure that results are valid
            foreach (var result in results)
            {
                Assert.AreEqual(result[0], fixedValue);
            }

            Debug.WriteLine(String.Format("Time to call {0} SMembers and MGet operations: {1} ms", count, sw.ElapsedMilliseconds));
            var opt = new SortOptions() { SortPattern = "nosort", GetPattern = "*" };

            sw = Stopwatch.StartNew();
            for (int i = 0; i < count; ++i)
                results = Redis.Sort(setKey, opt);
            sw.Stop();

            //make sure that results are valid
            foreach (var result in results)
            {
                Assert.AreEqual(result[0], fixedValue);
            }

            Debug.WriteLine(String.Format("Time to call {0} sort operations: {1} ms", count, sw.ElapsedMilliseconds));
        }
        public void SortStore(string listOrSetId, SortOptions sortOptions,string intoSetId)
        {
            var cmdWithArgs = new List<byte[]>
           	{
           		Commands.Sort, listOrSetId.ToUtf8Bytes()
           	};

            if (sortOptions.SortPattern != null)
            {
                cmdWithArgs.Add(Commands.By);
                cmdWithArgs.Add(sortOptions.SortPattern.ToUtf8Bytes());
            }

            if (sortOptions.Skip.HasValue || sortOptions.Take.HasValue)
            {
                cmdWithArgs.Add(Commands.Limit);
                cmdWithArgs.Add(sortOptions.Skip.GetValueOrDefault(0).ToUtf8Bytes());
                cmdWithArgs.Add(sortOptions.Take.GetValueOrDefault(0).ToUtf8Bytes());
            }

            if (sortOptions.GetPattern != null)
            {
                cmdWithArgs.Add(Commands.Get);
                cmdWithArgs.Add(sortOptions.GetPattern.ToUtf8Bytes());
            }

            if (sortOptions.SortDesc)
            {
                cmdWithArgs.Add(Commands.Desc);
            }

            if (sortOptions.SortAlpha)
            {
                cmdWithArgs.Add(Commands.Alpha);
            }
            cmdWithArgs.Add(Commands.Store);
            cmdWithArgs.Add(sortOptions.StoreAtKey.ToUtf8Bytes());
            SendExpectSuccess(cmdWithArgs.ToArray());
        }